Subversion Repositories Kolibri OS

Rev

Rev 3555 | Rev 5201 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3555 Rev 3725
Line 10... Line 10...
10
;;          GNU GENERAL PUBLIC LICENSE                          ;;
10
;;          GNU GENERAL PUBLIC LICENSE                          ;;
11
;;             Version 2, June 1991                             ;;
11
;;             Version 2, June 1991                             ;;
12
;;                                                              ;;
12
;;                                                              ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 14... Line 14...
14
 
14
 
Line 15... Line 15...
15
$Revision: 3555 $
15
$Revision: 3725 $
16
 
16
 
17
; The Queues implemented by these macros form a ring-buffer.
17
; The Queues implemented by these macros form a ring-buffer.
18
; The data to these queue's always looks like this:
18
; The data to these queue's always looks like this:
Line 26... Line 26...
26
struct	queue
26
struct  queue
Line 27... Line 27...
27
 
27
 
28
	size	       dd ?    ; number of queued packets in this queue
28
        size            dd ?    ; number of queued packets in this queue
29
	w_ptr	       dd ?    ; current writing pointer in queue
29
        w_ptr           dd ?    ; current writing pointer in queue
-
 
30
        r_ptr           dd ?    ; current reading pointer
Line 30... Line 31...
30
	r_ptr	       dd ?    ; current reading pointer
31
        mutex           MUTEX
Line 31... Line 32...
31
 
32
 
Line 42... Line 43...
42
; get_from_queue on the other hand will return a pointer in esi, to the entry you're interessed in
43
; get_from_queue on the other hand will return a pointer in esi, to the entry you're interessed in
43
; PS: macros WILL destroy ecx and edi
44
; PS: macros WILL destroy ecx and edi
Line 44... Line 45...
44
 
45
 
Line -... Line 46...
-
 
46
macro add_to_queue ptr, size, entry_size, failaddr {
-
 
47
 
-
 
48
local .ok, .no_wrap
-
 
49
 
-
 
50
        pusha
-
 
51
        lea     ecx, [ptr + queue.mutex]
-
 
52
        call    mutex_lock
45
macro add_to_queue ptr, size, entry_size, failaddr {
53
        popa
-
 
54
 
-
 
55
        cmp     [ptr + queue.size], size        ; Check if queue isnt full
-
 
56
        jb      .ok
-
 
57
 
-
 
58
        pusha
-
 
59
        lea     ecx, [ptr + queue.mutex]
46
 
60
        call    mutex_unlock
Line -... Line 61...
-
 
61
        popa
47
	cmp	[ptr + queue.size], size	; Check if queue isnt full
62
        jmp     failaddr
Line 48... Line 63...
48
	jae	failaddr
63
 
49
 
64
  .ok:
50
	inc	[ptr + queue.size]		; if not full, queue one more
65
        inc     [ptr + queue.size]              ; if not full, queue one more
Line 56... Line 71...
56
	lea	ecx, [size*entry_size+ptr+sizeof.queue]
71
        lea     ecx, [size*entry_size+ptr+sizeof.queue]
57
	cmp	edi, ecx			; entry size
72
        cmp     edi, ecx                        ; entry size
58
	jb	.no_wrap
73
        jb      .no_wrap
Line 59... Line 74...
59
 
74
 
60
	sub	edi, size*entry_size
-
 
61
 
75
        sub     edi, size*entry_size
62
  .no_wrap:
76
  .no_wrap:
Line -... Line 77...
-
 
77
        mov     [ptr + queue.w_ptr], edi
-
 
78
 
-
 
79
        pusha
-
 
80
        lea     ecx, [ptr + queue.mutex]
-
 
81
        call    mutex_unlock
63
	mov	[ptr + queue.w_ptr], edi
82
        popa
Line 64... Line 83...
64
 
83
 
Line -... Line 84...
-
 
84
}
-
 
85
 
-
 
86
 
-
 
87
 
-
 
88
macro get_from_queue ptr, size, entry_size,  failaddr {
-
 
89
 
-
 
90
local .ok, .no_wrap
65
}
91
 
-
 
92
        pusha
-
 
93
        lea     ecx, [ptr + queue.mutex]
-
 
94
        call    mutex_lock
-
 
95
        popa
-
 
96
 
-
 
97
        cmp     [ptr + queue.size], 0           ; any packets queued?
66
 
98
        ja      .ok
Line -... Line 99...
-
 
99
 
67
 
100
        pusha
Line 68... Line 101...
68
 
101
        lea     ecx, [ptr + queue.mutex]
69
macro get_from_queue ptr, size, entry_size,  failaddr {
102
        call    mutex_unlock
Line 87... Line 120...
87
  .no_wrap:
120
  .no_wrap:
88
	mov	dword [ptr + queue.r_ptr], esi
121
        mov     dword [ptr + queue.r_ptr], esi
Line 89... Line 122...
89
 
122
 
Line -... Line 123...
-
 
123
        pop     esi
-
 
124
 
-
 
125
        pusha
-
 
126
        lea     ecx, [ptr + queue.mutex]
-
 
127
        call    mutex_unlock
90
	pop	esi
128
        popa
Line 91... Line 129...
91
 
129
 
Line 92... Line 130...
92
}
130
}
93
 
131
 
94
macro init_queue ptr {
132
macro init_queue ptr {
95
 
133
 
-
 
134
        mov     [ptr + queue.size] , 0
-
 
135
        lea     edi, [ptr + sizeof.queue]
-
 
136
        mov     [ptr + queue.w_ptr], edi
96
	mov	[ptr + queue.size] , 0
137
        mov     [ptr + queue.r_ptr], edi
97
	lea	edi, [ptr + sizeof.queue]
138