diff options
author | inmarket <andrewh@inmarket.com.au> | 2014-03-14 07:38:02 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2014-03-14 07:38:02 +1000 |
commit | 6f54bde79c553301a35535a0a71a4a09b181abfa (patch) | |
tree | 1408ad80459cd09da47960b4905d50195916639d /src/gqueue/gqueue.c | |
parent | 6d372f13528f44919ec193d03248d55a53484968 (diff) | |
parent | ea5a1b849df6e5085a92957ad387f9e653674415 (diff) | |
download | uGFX-6f54bde79c553301a35535a0a71a4a09b181abfa.tar.gz uGFX-6f54bde79c553301a35535a0a71a4a09b181abfa.tar.bz2 uGFX-6f54bde79c553301a35535a0a71a4a09b181abfa.zip |
Merge branch 'master' into freertos
Diffstat (limited to 'src/gqueue/gqueue.c')
-rw-r--r-- | src/gqueue/gqueue.c | 137 |
1 files changed, 84 insertions, 53 deletions
diff --git a/src/gqueue/gqueue.c b/src/gqueue/gqueue.c index 2adfd9ff..b7ecb032 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 @@ -122,40 +138,57 @@ return pi; } + gfxQueueGSyncItem *gfxQueueGSyncGetI(gfxQueueGSync *pqueue) { + gfxQueueGSyncItem *pi; - void gfxQueueGSyncPut(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { - pitem->next = 0; + 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(); + 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 +205,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 +245,7 @@ pi->next = 0; gfxSystemUnlock(); - gfxSemSignalI(&pi->sem); + gfxSemSignal(&pi->sem); gfxSemDestroy(&pi->sem); return pi; @@ -281,25 +313,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 */ - |