7 typedef struct vg_queue vg_queue
;
8 typedef struct vg_queue_frame vg_queue_frame
;
10 struct vg_queue_frame
{
19 vg_queue_frame
*head
, *tail
;
23 * Allocate memory on the queue. Returns NULL if allocation failed for any
26 static vg_queue_frame
*vg_queue_alloc( vg_queue
*q
, u32 size
){
27 u32 total
= vg_align8(size
) + sizeof(vg_queue_frame
);
28 vg_queue_frame
*frame
= NULL
;
34 u32 end
= ((u8
*)q
->head
- q
->buffer
) + q
->head
->alloc_size
,
35 start
= ((u8
*)q
->tail
- q
->buffer
),
47 frame
= (vg_queue_frame
*)(q
->buffer
+ end
);
51 q
->head
->alloc_size
+= r0
;
52 frame
= (vg_queue_frame
*)q
->buffer
;
56 if( !frame
) return NULL
;
59 frame
= (vg_queue_frame
*)q
->buffer
;
63 memset( frame
, 0, sizeof(vg_queue_frame
) );
66 frame
->alloc_size
= total
;
73 * Free last item from queue
75 static void vg_queue_pop( vg_queue
*q
){
76 if( q
->head
== q
->tail
){
82 u32 start
= ((u8
*)q
->tail
- q
->buffer
);
83 start
+= q
->tail
->alloc_size
;
85 if( start
== q
->size
)
88 q
->tail
= (vg_queue_frame
*)(q
->buffer
+ start
);
91 #endif /* VG_MEM_QUEUE_H */