Usage of new mutexes in net branch.

git-svn-id: svn://kolibrios.org@2402 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-02-25 12:03:22 +00:00
parent 0478f45357
commit 815cb2a26f
6 changed files with 1058 additions and 1002 deletions

View File

@ -254,9 +254,10 @@ ICMP_input:
DEBUGF 1,"Found valid ICMP packet for socket %x\n", ebx
mov eax, ebx
add ebx, SOCKET.lock
call wait_mutex
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_lock
popa
mov esi, edx
jmp SOCKET_input

View File

@ -22,7 +22,7 @@ struct SOCKET
PrevPtr dd ? ; pointer to previous socket in list
Number dd ? ; socket number
lock dd ? ; lock mutex
mutex MUTEX
PID dd ? ; application process id
Domain dd ? ; INET/UNIX/..
@ -450,8 +450,10 @@ SOCKET_connect:
align 4
.udp:
lea ebx, [eax + SOCKET.lock]
call wait_mutex
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_lock
popa
pushw [edx + 2]
pop [eax + UDP_SOCKET.RemotePort]
@ -470,14 +472,18 @@ align 4
init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue
pop eax
mov [eax + SOCKET.lock], 0
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
mov dword [esp+32], 0
ret
align 4
.tcp:
lea ebx, [eax + SOCKET.lock]
call wait_mutex
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_lock
popa
pushw [edx + 2]
pop [eax + TCP_SOCKET.RemotePort]
@ -509,7 +515,10 @@ align 4
lea eax, [ebx + STREAM_SOCKET.rcv]
call SOCKET_ring_create
mov [ebx + SOCKET.lock], 0
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
popa
mov eax, ebx
call TCP_output
@ -519,8 +528,10 @@ align 4
align 4
.ip:
lea ebx, [eax + SOCKET.lock]
call wait_mutex
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_lock
popa
pushd [edx + 4]
pop [eax + IP_SOCKET.RemoteIP]
@ -529,7 +540,9 @@ align 4
init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue
pop eax
mov [eax + SOCKET.lock], 0
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
mov dword [esp+32], 0
ret
@ -1051,12 +1064,22 @@ SOCKET_input:
DEBUGF 1,"SOCKET_input: queued packet successfully\n"
add esp, sizeof.socket_queue_entry
mov [eax + SOCKET.lock], 0
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
popa
jmp SOCKET_notify_owner
.full:
DEBUGF 2,"SOCKET_input: socket %x is full!\n", eax
mov [eax + SOCKET.lock], 0
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
popa
call kernel_free
add esp, 8
@ -1364,11 +1387,18 @@ SOCKET_alloc:
test ebx, ebx
jz @f
add ebx, SOCKET.lock ; lock the next socket
call wait_mutex
sub ebx, SOCKET.lock
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_lock
popa
mov [ebx + SOCKET.PrevPtr], eax
mov [ebx + SOCKET.lock], 0 ; and unlock it again
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
popa
@@:
mov [net_sockets + SOCKET.NextPtr], eax
@ -1398,8 +1428,11 @@ SOCKET_free:
jz .error
push ebx
lea ebx, [eax + SOCKET.lock]
call wait_mutex
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_lock
popa
DEBUGF 1, "SOCKET_free: freeing socket..\n"

View File

@ -151,12 +151,6 @@ macro ntohw reg {
}
wait_mutex: ; stub
inc dword [ebx]
ret
include "queue.inc"
include "ethernet.inc"

View File

@ -143,13 +143,10 @@ TCP_input:
;----------------
; Lock the socket
cmp [ebx + SOCKET.lock], 0
jne .drop_not_locked ;;; HACK ! HACK ! dirty fucking HACK ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
add ebx, SOCKET.lock
DEBUGF 1,"lock: %x\n", [ebx]
call wait_mutex
sub ebx, SOCKET.lock
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_lock
popa
DEBUGF 1,"Socket locked\n"
@ -171,7 +168,11 @@ TCP_input:
DEBUGF 1,"Accepting new connection\n"
mov [ebx + SOCKET.lock], 0
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
popa
push ecx edx esi edi ;;;
call SOCKET_fork
pop edi esi edx ecx
@ -375,7 +376,11 @@ TCP_input:
mov [ebx + TCP_SOCKET.timer_retransmission], 0
; Awaken waiting processes
mov [ebx + SOCKET.lock], 0
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
popa
mov eax, ebx
call SOCKET_notify_owner
@ -1465,7 +1470,10 @@ align 4
.dumpit:
mov [ebx + SOCKET.lock], 0
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
popa
call kernel_free
add esp, 4
@ -1490,7 +1498,10 @@ align 4
and [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
mov [ebx + SOCKET.lock], 0
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
popa
push ebx
; mov cl, TH_ACK
@ -1516,7 +1527,10 @@ align 4
align 4
.drop_with_reset:
mov [ebx + SOCKET.lock], 0
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
popa
.drop_with_reset_not_locked:
@ -1568,7 +1582,10 @@ align 4
align 4
.drop:
mov [ebx + SOCKET.lock], 0
pusha
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
popa
.drop_not_locked:

View File

@ -264,7 +264,10 @@ TCP_output:
DEBUGF 1,"No reason to send a segment\n"
mov [eax + SOCKET.lock], 0
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
popa
ret
@ -511,7 +514,10 @@ TCP_output:
; unlock socket
mov [eax + SOCKET.lock], 0
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
popa
;----------------
; Send the packet
@ -526,7 +532,12 @@ TCP_output:
add esp, ecx
pop eax
add esp, 8
mov [eax + SOCKET.lock], 0
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
popa
DEBUGF 1,"TCP_output: failed\n"
ret

View File

@ -178,10 +178,10 @@ UDP_input:
cmp [eax + UDP_SOCKET.RemotePort], cx
jne .dump
push ebx
lea ebx, [eax + SOCKET.lock]
call wait_mutex
pop ebx
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_lock
popa
.updatesock:
inc [UDP_PACKETS_RX]
@ -193,10 +193,10 @@ UDP_input:
jmp SOCKET_input
.updateport:
push ebx
lea ebx, [eax + SOCKET.lock]
call wait_mutex
pop ebx
pusha
lea ecx, [eax + SOCKET.mutex]
call mutex_lock
popa
DEBUGF 1,"Changing remote port to: %u\n", cx
mov [eax + UDP_SOCKET.RemotePort], cx