7 typedef struct vg_queue vg_queue
;
8 typedef struct vg_queue_frame vg_queue_frame
;
14 struct vg_queue_frame
{
22 * Allocate memory on the queue. Returns NULL if allocation failed for any
25 static vg_queue_frame
*vg_queue_alloc( vg_queue
*q
, u32 size
){
26 u32 total
= vg_align8(size
) + sizeof(vg_queue_frame
);
27 vg_queue_frame
*frame
= NULL
;
33 u32 end
= ((u8
*)q
->head
- q
->buffer
) + q
->head
->alloc_size
,
34 start
= ((u8
*)q
->tail
- q
->buffer
),
46 frame
= (vg_queue_frame
*)(q
->buffer
+ end
);
50 q
->head
->alloc_size
+= r0
;
51 frame
= (vg_queue_frame
*)q
->buffer
;
55 if( !frame
) return NULL
;
58 frame
= (vg_queue_frame
*)q
->buffer
;
62 memset( frame
, 0, sizeof(vg_queue_frame
) );
65 frame
->alloc_size
= total
;
72 * Free last item from queue
74 static void vg_queue_pop( vg_queue
*q
){
75 if( q
->head
== q
->tail
){
81 u32 start
= ((u8
*)q
->tail
- q
->buffer
);
82 start
+= q
->tail
->alloc_size
;
84 if( start
== q
->size
)
87 q
->tail
= (vg_queue_frame
*)(q
->buffer
+ start
);
90 #endif /* VG_MEM_QUEUE_H */