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 DEBUGF 1,"Found valid ICMP packet for socket %x\n", ebx
mov eax, ebx pusha
add ebx, SOCKET.lock lea ecx, [eax + SOCKET.mutex]
call wait_mutex call mutex_lock
popa
mov esi, edx mov esi, edx
jmp SOCKET_input jmp SOCKET_input

View File

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

View File

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

View File

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

View File

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