Subversion Repositories Kolibri OS

Rev

Rev 3555 | Rev 5201 | Go to most recent revision | Show entire file | Ignore 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:
19
;
19
;
20
; At top, you have the queue struct, wich has the size (number of currently queued packets, read and write pointers.
20
; At top, you have the queue struct, wich has the size (number of currently queued packets, read and write pointers.
21
; This struct is followed by a number of slots wich you can read and write to using the macros.
21
; This struct is followed by a number of slots wich you can read and write to using the macros.
Line 22... Line 22...
22
; How these slots look like is up to you to chose, normally they should have at least a pointer to where the real data is.
22
; How these slots look like is up to you to chose, normally they should have at least a pointer to where the real data is.
Line 23... Line 23...
23
; (you can see some examples below)
23
; (you can see some examples below)
24
 
24
 
25
 
25
 
-
 
26
struct  queue
Line 26... Line 27...
26
struct	queue
27
 
Line 27... Line 28...
27
 
28
        size            dd ?    ; number of queued packets in this queue
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 45... Line -...
45
macro add_to_queue ptr, size, entry_size, failaddr {
-
 
46
 
46
macro add_to_queue ptr, size, entry_size, failaddr {
Line -... Line 47...
-
 
47
 
-
 
48
local .ok, .no_wrap
-
 
49
 
-
 
50
        pusha
-
 
51
        lea     ecx, [ptr + queue.mutex]
-
 
52
        call    mutex_lock
-
 
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]
-
 
60
        call    mutex_unlock
-
 
61
        popa
47
	cmp	[ptr + queue.size], size	; Check if queue isnt full
62
        jmp     failaddr
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
51
 
66
 
52
	mov	edi, [ptr + queue.w_ptr]	; Current write pointer (FIFO!)
67
        mov     edi, [ptr + queue.w_ptr]        ; Current write pointer (FIFO!)
53
	mov	ecx, entry_size/4		; Write the queue entry
68
        mov     ecx, entry_size/4               ; Write the queue entry
54
	rep	movsd				;
69
        rep movsd                               ;
55
 
70
 
56
	lea	ecx, [size*entry_size+ptr+sizeof.queue]
-
 
57
	cmp	edi, ecx			; entry size
-
 
Line -... Line 71...
-
 
71
        lea     ecx, [size*entry_size+ptr+sizeof.queue]
58
	jb	.no_wrap
72
        cmp     edi, ecx                        ; entry size
59
 
73
        jb      .no_wrap
-
 
74
 
-
 
75
        sub     edi, size*entry_size
-
 
76
  .no_wrap:
-
 
77
        mov     [ptr + queue.w_ptr], edi
-
 
78
 
Line 60... Line 79...
60
	sub	edi, size*entry_size
79
        pusha
Line 61... Line 80...
61
 
80
        lea     ecx, [ptr + queue.mutex]
Line -... Line 81...
-
 
81
        call    mutex_unlock
-
 
82
        popa
-
 
83
 
62
  .no_wrap:
84
}
-
 
85
 
63
	mov	[ptr + queue.w_ptr], edi
86
 
Line 64... Line 87...
64
 
87
 
-
 
88
macro get_from_queue ptr, size, entry_size,  failaddr {
Line -... Line 89...
-
 
89
 
65
}
90
local .ok, .no_wrap
-
 
91
 
66
 
92
        pusha
-
 
93
        lea     ecx, [ptr + queue.mutex]
Line 67... Line 94...
67
 
94
        call    mutex_lock
-
 
95
        popa
Line 68... Line 96...
68
 
96
 
69
macro get_from_queue ptr, size, entry_size,  failaddr {
97
        cmp     [ptr + queue.size], 0           ; any packets queued?
70
 
-
 
Line -... Line 98...
-
 
98
        ja      .ok
-
 
99
 
-
 
100
        pusha
-
 
101
        lea     ecx, [ptr + queue.mutex]
-
 
102
        call    mutex_unlock
-
 
103
        popa
71
	cmp	[ptr + queue.size], 0		; any packets queued?
104
        jmp     failaddr
Line 72... Line 105...
72
	je	failaddr
105
 
73
 
106
  .ok:
Line 74... Line 107...
74
	dec	[ptr + queue.size]		; if so, dequeue one
107
        dec     [ptr + queue.size]              ; if so, dequeue one
-
 
108
 
-
 
109
        mov     esi, [ptr + queue.r_ptr]
-
 
110
        push    esi
-
 
111
 
-
 
112
        add     esi, entry_size
Line 75... Line 113...
75
 
113
 
Line 76... Line 114...
76
	mov	esi, [ptr + queue.r_ptr]
114
        lea     ecx, [size*entry_size+ptr+sizeof.queue]
Line 77... Line 115...
77
	push	esi
115
        cmp     esi, ecx                        ; entry size
78
 
116
        jb      .no_wrap
79
	add	esi, entry_size
117
 
80
 
118
        sub     esi, size*entry_size
-
 
119
 
-
 
120
  .no_wrap:
-
 
121
        mov     dword [ptr + queue.r_ptr], esi
81
	lea	ecx, [size*entry_size+ptr+sizeof.queue]
122
 
82
	cmp	esi, ecx			; entry size
123
        pop     esi