From 17f1f9d7990461cbdb7b40d42b310321ca47b776 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 3 Mar 2014 07:38:57 +1000 Subject: Add I class rouitines to GQUEUE --- src/gqueue/gqueue.c | 126 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 73 insertions(+), 53 deletions(-) (limited to 'src/gqueue/gqueue.c') diff --git a/src/gqueue/gqueue.c b/src/gqueue/gqueue.c index 2adfd9ff..f3da1cdf 100644 --- a/src/gqueue/gqueue.c +++ b/src/gqueue/gqueue.c @@ -22,47 +22,64 @@ gfxQueueASyncItem *gfxQueueASyncGet(gfxQueueASync *pqueue) { gfxQueueASyncItem *pi; + // This is just a shortcut to speed execution if (!pqueue->head) return 0; gfxSystemLock(); - if ((pi = pqueue->head)) - pqueue->head = pi->next; - pi->next = 0; + pi = gfxQueueASyncGetI(pqueue); gfxSystemUnlock(); return pi; } + gfxQueueASyncItem *gfxQueueASyncGetI(gfxQueueASync *pqueue) { + gfxQueueASyncItem *pi; - void gfxQueueASyncPut(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { - pitem->next = 0; + if ((pi = pqueue->head)) { + pqueue->head = pi->next; + pi->next = 0; + } + + return pi; + } + void gfxQueueASyncPut(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { gfxSystemLock(); + gfxQueueASyncPutI(pqueue, pitem); + gfxSystemUnlock(); + } + void gfxQueueASyncPutI(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { + pitem->next = 0; if (!pqueue->head) { pqueue->head = pqueue->tail = pitem; } else { pqueue->tail->next = pitem; pqueue->tail = pitem; } - gfxSystemUnlock(); } void gfxQueueASyncPush(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { gfxSystemLock(); + gfxQueueASyncPushI(pqueue, pitem); + gfxSystemUnlock(); + } + void gfxQueueASyncPushI(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { pitem->next = pqueue->head; pqueue->head = pitem; if (!pitem->next) pqueue->tail = pitem; - gfxSystemUnlock(); } void gfxQueueASyncRemove(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { + gfxSystemLock(); + gfxQueueASyncRemoveI(pqueue, pitem); + gfxSystemUnlock(); + } + void gfxQueueASyncRemoveI(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { gfxQueueASyncItem *pi; if (!pitem) return; - - gfxSystemLock(); if (pqueue->head) { if (pqueue->head == pitem) { pqueue->head = pitem->next; @@ -79,25 +96,24 @@ } } } - gfxSystemUnlock(); - } - - bool_t gfxQueueASyncIsEmpty(gfxQueueASync *pqueue) { - return pqueue->head == 0; } bool_t gfxQueueASyncIsIn(gfxQueueASync *pqueue, const gfxQueueASyncItem *pitem) { - gfxQueueASyncItem *pi; + bool_t res; gfxSystemLock(); + res = gfxQueueASyncIsInI(pqueue, pitem); + gfxSystemUnlock(); + + return res; + } + bool_t gfxQueueASyncIsInI(gfxQueueASync *pqueue, const gfxQueueASyncItem *pitem) { + gfxQueueASyncItem *pi; + for(pi = pqueue->head; pi; pi = pi->next) { - if (pi == pitem) { - gfxSystemUnlock(); + if (pi == pitem) return TRUE; - } } - gfxSystemUnlock(); - return FALSE; } #endif @@ -124,38 +140,44 @@ } void gfxQueueGSyncPut(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { - pitem->next = 0; - gfxSystemLock(); + gfxQueueGSyncPutI(pqueue, pitem); + gfxSystemUnlock(); + } + void gfxQueueGSyncPutI(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { + pitem->next = 0; if (!pqueue->head) { pqueue->head = pqueue->tail = pitem; } else { pqueue->tail->next = pitem; pqueue->tail = pitem; } - gfxSystemUnlock(); - - gfxSemSignal(&pqueue->sem); + gfxSemSignalI(&pqueue->sem); } void gfxQueueGSyncPush(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { gfxSystemLock(); + gfxQueueGSyncPushI(pqueue, pitem); + gfxSystemUnlock(); + } + void gfxQueueGSyncPushI(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { pitem->next = pqueue->head; pqueue->head = pitem; if (!pitem->next) pqueue->tail = pitem; - gfxSystemUnlock(); - - gfxSemSignal(&pqueue->sem); + gfxSemSignalI(&pqueue->sem); } void gfxQueueGSyncRemove(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { + gfxSystemLock(); + gfxQueueGSyncRemoveI(pqueue, pitem); + gfxSystemUnlock(); + } + void gfxQueueGSyncRemoveI(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { gfxQueueGSyncItem *pi; if (!pitem) return; - - gfxSystemLock(); if (pqueue->head) { if (pqueue->head == pitem) { pqueue->head = pitem->next; @@ -172,25 +194,24 @@ } } } - gfxSystemUnlock(); - } - - bool_t gfxQueueGSyncIsEmpty(gfxQueueGSync *pqueue) { - return pqueue->head == 0; } bool_t gfxQueueGSyncIsIn(gfxQueueGSync *pqueue, const gfxQueueGSyncItem *pitem) { - gfxQueueGSyncItem *pi; + bool_t res; gfxSystemLock(); + res = gfxQueueGSyncIsInI(pqueue, pitem); + gfxSystemUnlock(); + + return res; + } + bool_t gfxQueueGSyncIsInI(gfxQueueGSync *pqueue, const gfxQueueGSyncItem *pitem) { + gfxQueueGSyncItem *pi; + for(pi = pqueue->head; pi; pi = pi->next) { - if (pi == pitem) { - gfxSystemUnlock(); + if (pi == pitem) return TRUE; - } } - gfxSystemUnlock(); - return FALSE; } #endif @@ -213,7 +234,7 @@ pi->next = 0; gfxSystemUnlock(); - gfxSemSignalI(&pi->sem); + gfxSemSignal(&pi->sem); gfxSemDestroy(&pi->sem); return pi; @@ -281,25 +302,24 @@ gfxSystemUnlock(); } - bool_t gfxQueueFSyncIsEmpty(gfxQueueFSync *pqueue) { - return pqueue->head == 0; - } - bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem) { - gfxQueueASyncItem *pi; + bool_t res; gfxSystemLock(); + res = gfxQueueFSyncIsInI(pqueue, pitem); + gfxSystemUnlock(); + + return res; + } + bool_t gfxQueueFSyncIsInI(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem) { + gfxQueueASyncItem *pi; + for(pi = pqueue->head; pi; pi = pi->next) { - if (pi == pitem) { - gfxSystemUnlock(); + if (pi == pitem) return TRUE; - } } - gfxSystemUnlock(); - return FALSE; } #endif #endif /* GFX_USE_GQUEUE */ - -- cgit v1.2.3 From 944c33cbff5f2cfb1c80f48193aa2161574864fd Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 11 Mar 2014 17:11:02 +1000 Subject: Add support for gfxQueueGSyncGetI() --- src/gqueue/gqueue.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/gqueue/gqueue.c') diff --git a/src/gqueue/gqueue.c b/src/gqueue/gqueue.c index f3da1cdf..b7ecb032 100644 --- a/src/gqueue/gqueue.c +++ b/src/gqueue/gqueue.c @@ -138,6 +138,17 @@ return pi; } + gfxQueueGSyncItem *gfxQueueGSyncGetI(gfxQueueGSync *pqueue) { + gfxQueueGSyncItem *pi; + + if (!gfxSemWaitI(&pqueue->sem)) + return 0; + + pi = pqueue->head; + pqueue->head = pi->next; + pi->next = 0; + return pi; + } void gfxQueueGSyncPut(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { gfxSystemLock(); -- cgit v1.2.3