1 #include "vg_platform.h"
3 #include "vg_mem_queue.h"
8 * Allocate memory on the queue. Returns NULL if allocation failed for any
11 vg_queue_frame
*vg_queue_alloc( vg_queue
*q
, u32 size
)
13 u32 total
= vg_align8(size
) + sizeof(vg_queue_frame
);
14 vg_queue_frame
*frame
= NULL
;
21 u32 end
= ((u8
*)q
->head
- q
->buffer
) + q
->head
->alloc_size
,
22 start
= ((u8
*)q
->tail
- q
->buffer
),
34 frame
= (vg_queue_frame
*)(q
->buffer
+ end
);
38 q
->head
->alloc_size
+= r0
;
39 frame
= (vg_queue_frame
*)q
->buffer
;
43 if( !frame
) return NULL
;
46 frame
= (vg_queue_frame
*)q
->buffer
;
50 memset( frame
, 0, sizeof(vg_queue_frame
) );
53 frame
->alloc_size
= total
;
60 * Free last item from queue
62 void vg_queue_pop( vg_queue
*q
)
64 if( q
->head
== q
->tail
){
70 u32 start
= ((u8
*)q
->tail
- q
->buffer
);
71 start
+= q
->tail
->alloc_size
;
73 if( start
== q
->size
)
76 q
->tail
= (vg_queue_frame
*)(q
->buffer
+ start
);