2009-09-17 13:55:38 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2009-10-05 22:47:27 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
|
2009-09-17 13:55:38 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; queue.inc ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2009-10-12 16:39:59 +02:00
|
|
|
$Revision$
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
; The Queues implemented by these macros for a sort of ring-buffer.
|
|
|
|
; The data to these queue's always looks like this:
|
|
|
|
;
|
|
|
|
; At top, you have the queue struct, wich has the size (number of currently queued packets, read and write pointers.
|
|
|
|
; This struct is followed by a number of slots wich you can read and write to using the macros.
|
|
|
|
; 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.
|
|
|
|
; (you can see some examples below)
|
|
|
|
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
struct queue
|
2009-11-06 21:45:08 +01:00
|
|
|
.size dd ? ; number of queued packets in thsi queue
|
|
|
|
.w_ptr dd ? ; current writing pointer in queue
|
|
|
|
.r_ptr dd ? ; current reading pointer
|
2009-09-17 13:55:38 +02:00
|
|
|
.data:
|
|
|
|
ends
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
; The following macros share these inputs:
|
|
|
|
|
|
|
|
; ptr = pointer to where the queue data is located
|
|
|
|
; size = number of slots/entrys in the queue
|
|
|
|
; entry_size = size of one slot, in bytes
|
|
|
|
; failaddr = the address where macro will jump to when there is no data in the queue
|
|
|
|
|
|
|
|
; additionally, add_to_queue requires you to set esi to the data wich you want to queue
|
|
|
|
; get_from_queue on the other hand will return a pointer in esi, to the entry you're interessed in
|
|
|
|
; PS: macros WILL destroy ecx and edi
|
|
|
|
|
2009-11-06 21:45:08 +01:00
|
|
|
macro add_to_queue ptr, size, entry_size, failaddr {
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
cmp [ptr + queue.size], size ; Check if queue isnt full
|
2009-11-06 21:45:08 +01:00
|
|
|
jge failaddr
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
inc [ptr + queue.size] ; if not full, queue one more
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
mov edi, [ptr + queue.w_ptr] ; Current write pointer (FIFO!)
|
2009-11-06 21:45:08 +01:00
|
|
|
mov ecx, entry_size/4 ; Write the queue entry
|
|
|
|
rep movsd ;
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-06 21:45:08 +01:00
|
|
|
lea ecx, [size*entry_size+ptr+queue.data]
|
2009-11-09 14:59:46 +01:00
|
|
|
cmp edi, ecx ; entry size
|
2009-09-17 13:55:38 +02:00
|
|
|
jl .no_wrap
|
|
|
|
|
2009-11-06 21:45:08 +01:00
|
|
|
sub edi, size*entry_size
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.no_wrap:
|
2009-11-06 21:45:08 +01:00
|
|
|
mov [ptr + queue.w_ptr], edi
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-06 21:45:08 +01:00
|
|
|
macro get_from_queue ptr, size, entry_size, failaddr {
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
cmp [ptr + queue.size], 0 ; any packets queued?
|
2009-11-06 21:45:08 +01:00
|
|
|
je failaddr
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
dec [ptr + queue.size] ; if so, dequeue one
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
mov esi, [ptr + queue.r_ptr]
|
2009-11-06 21:45:08 +01:00
|
|
|
push esi
|
|
|
|
|
|
|
|
add esi, entry_size
|
|
|
|
|
|
|
|
lea ecx, [size*entry_size+ptr+queue.data]
|
2009-11-09 14:59:46 +01:00
|
|
|
cmp esi, ecx ; entry size
|
2009-09-17 13:55:38 +02:00
|
|
|
jl .no_wrap
|
|
|
|
|
2009-11-06 21:45:08 +01:00
|
|
|
sub esi, size*entry_size
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
.no_wrap:
|
|
|
|
mov dword [ptr + queue.r_ptr], esi
|
|
|
|
|
2009-11-06 21:45:08 +01:00
|
|
|
pop esi
|
|
|
|
|
2009-09-17 13:55:38 +02:00
|
|
|
}
|
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
macro init_queue ptr {
|
2009-11-06 21:45:08 +01:00
|
|
|
|
2009-11-09 14:59:46 +01:00
|
|
|
mov [ptr + queue.size] , 0
|
|
|
|
lea edi, [ptr + queue.data]
|
|
|
|
mov [ptr + queue.w_ptr], edi
|
|
|
|
mov [ptr + queue.r_ptr], edi
|
2009-11-06 21:45:08 +01:00
|
|
|
}
|