Add I class rouitines to GQUEUE

ugfx_release_2.6
inmarket 2014-03-03 07:38:57 +10:00
parent 4b167f5624
commit 17f1f9d799
2 changed files with 109 additions and 59 deletions

View File

@ -22,47 +22,64 @@
gfxQueueASyncItem *gfxQueueASyncGet(gfxQueueASync *pqueue) { gfxQueueASyncItem *gfxQueueASyncGet(gfxQueueASync *pqueue) {
gfxQueueASyncItem *pi; gfxQueueASyncItem *pi;
// This is just a shortcut to speed execution
if (!pqueue->head) if (!pqueue->head)
return 0; return 0;
gfxSystemLock(); gfxSystemLock();
if ((pi = pqueue->head)) pi = gfxQueueASyncGetI(pqueue);
pqueue->head = pi->next;
pi->next = 0;
gfxSystemUnlock(); gfxSystemUnlock();
return pi; return pi;
} }
gfxQueueASyncItem *gfxQueueASyncGetI(gfxQueueASync *pqueue) {
gfxQueueASyncItem *pi;
if ((pi = pqueue->head)) {
pqueue->head = pi->next;
pi->next = 0;
}
return pi;
}
void gfxQueueASyncPut(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { void gfxQueueASyncPut(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) {
pitem->next = 0;
gfxSystemLock(); gfxSystemLock();
gfxQueueASyncPutI(pqueue, pitem);
gfxSystemUnlock();
}
void gfxQueueASyncPutI(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) {
pitem->next = 0;
if (!pqueue->head) { if (!pqueue->head) {
pqueue->head = pqueue->tail = pitem; pqueue->head = pqueue->tail = pitem;
} else { } else {
pqueue->tail->next = pitem; pqueue->tail->next = pitem;
pqueue->tail = pitem; pqueue->tail = pitem;
} }
gfxSystemUnlock();
} }
void gfxQueueASyncPush(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { void gfxQueueASyncPush(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) {
gfxSystemLock(); gfxSystemLock();
gfxQueueASyncPushI(pqueue, pitem);
gfxSystemUnlock();
}
void gfxQueueASyncPushI(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) {
pitem->next = pqueue->head; pitem->next = pqueue->head;
pqueue->head = pitem; pqueue->head = pitem;
if (!pitem->next) if (!pitem->next)
pqueue->tail = pitem; pqueue->tail = pitem;
gfxSystemUnlock();
} }
void gfxQueueASyncRemove(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { void gfxQueueASyncRemove(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) {
gfxSystemLock();
gfxQueueASyncRemoveI(pqueue, pitem);
gfxSystemUnlock();
}
void gfxQueueASyncRemoveI(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) {
gfxQueueASyncItem *pi; gfxQueueASyncItem *pi;
if (!pitem) if (!pitem)
return; return;
gfxSystemLock();
if (pqueue->head) { if (pqueue->head) {
if (pqueue->head == pitem) { if (pqueue->head == pitem) {
pqueue->head = pitem->next; 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) { bool_t gfxQueueASyncIsIn(gfxQueueASync *pqueue, const gfxQueueASyncItem *pitem) {
gfxQueueASyncItem *pi; bool_t res;
gfxSystemLock(); gfxSystemLock();
for(pi = pqueue->head; pi; pi = pi->next) { res = gfxQueueASyncIsInI(pqueue, pitem);
if (pi == pitem) {
gfxSystemUnlock();
return TRUE;
}
}
gfxSystemUnlock(); gfxSystemUnlock();
return res;
}
bool_t gfxQueueASyncIsInI(gfxQueueASync *pqueue, const gfxQueueASyncItem *pitem) {
gfxQueueASyncItem *pi;
for(pi = pqueue->head; pi; pi = pi->next) {
if (pi == pitem)
return TRUE;
}
return FALSE; return FALSE;
} }
#endif #endif
@ -124,38 +140,44 @@
} }
void gfxQueueGSyncPut(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { void gfxQueueGSyncPut(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) {
pitem->next = 0;
gfxSystemLock(); gfxSystemLock();
gfxQueueGSyncPutI(pqueue, pitem);
gfxSystemUnlock();
}
void gfxQueueGSyncPutI(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) {
pitem->next = 0;
if (!pqueue->head) { if (!pqueue->head) {
pqueue->head = pqueue->tail = pitem; pqueue->head = pqueue->tail = pitem;
} else { } else {
pqueue->tail->next = pitem; pqueue->tail->next = pitem;
pqueue->tail = pitem; pqueue->tail = pitem;
} }
gfxSystemUnlock(); gfxSemSignalI(&pqueue->sem);
gfxSemSignal(&pqueue->sem);
} }
void gfxQueueGSyncPush(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { void gfxQueueGSyncPush(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) {
gfxSystemLock(); gfxSystemLock();
gfxQueueGSyncPushI(pqueue, pitem);
gfxSystemUnlock();
}
void gfxQueueGSyncPushI(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) {
pitem->next = pqueue->head; pitem->next = pqueue->head;
pqueue->head = pitem; pqueue->head = pitem;
if (!pitem->next) if (!pitem->next)
pqueue->tail = pitem; pqueue->tail = pitem;
gfxSystemUnlock(); gfxSemSignalI(&pqueue->sem);
gfxSemSignal(&pqueue->sem);
} }
void gfxQueueGSyncRemove(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { void gfxQueueGSyncRemove(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) {
gfxSystemLock();
gfxQueueGSyncRemoveI(pqueue, pitem);
gfxSystemUnlock();
}
void gfxQueueGSyncRemoveI(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) {
gfxQueueGSyncItem *pi; gfxQueueGSyncItem *pi;
if (!pitem) if (!pitem)
return; return;
gfxSystemLock();
if (pqueue->head) { if (pqueue->head) {
if (pqueue->head == pitem) { if (pqueue->head == pitem) {
pqueue->head = pitem->next; 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) { bool_t gfxQueueGSyncIsIn(gfxQueueGSync *pqueue, const gfxQueueGSyncItem *pitem) {
gfxQueueGSyncItem *pi; bool_t res;
gfxSystemLock(); gfxSystemLock();
for(pi = pqueue->head; pi; pi = pi->next) { res = gfxQueueGSyncIsInI(pqueue, pitem);
if (pi == pitem) {
gfxSystemUnlock();
return TRUE;
}
}
gfxSystemUnlock(); gfxSystemUnlock();
return res;
}
bool_t gfxQueueGSyncIsInI(gfxQueueGSync *pqueue, const gfxQueueGSyncItem *pitem) {
gfxQueueGSyncItem *pi;
for(pi = pqueue->head; pi; pi = pi->next) {
if (pi == pitem)
return TRUE;
}
return FALSE; return FALSE;
} }
#endif #endif
@ -213,7 +234,7 @@
pi->next = 0; pi->next = 0;
gfxSystemUnlock(); gfxSystemUnlock();
gfxSemSignalI(&pi->sem); gfxSemSignal(&pi->sem);
gfxSemDestroy(&pi->sem); gfxSemDestroy(&pi->sem);
return pi; return pi;
@ -281,25 +302,24 @@
gfxSystemUnlock(); gfxSystemUnlock();
} }
bool_t gfxQueueFSyncIsEmpty(gfxQueueFSync *pqueue) {
return pqueue->head == 0;
}
bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem) { bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem) {
gfxQueueASyncItem *pi; bool_t res;
gfxSystemLock(); gfxSystemLock();
for(pi = pqueue->head; pi; pi = pi->next) { res = gfxQueueFSyncIsInI(pqueue, pitem);
if (pi == pitem) {
gfxSystemUnlock();
return TRUE;
}
}
gfxSystemUnlock(); gfxSystemUnlock();
return res;
}
bool_t gfxQueueFSyncIsInI(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem) {
gfxQueueASyncItem *pi;
for(pi = pqueue->head; pi; pi = pi->next) {
if (pi == pitem)
return TRUE;
}
return FALSE; return FALSE;
} }
#endif #endif
#endif /* GFX_USE_GQUEUE */ #endif /* GFX_USE_GQUEUE */

View File

@ -105,10 +105,13 @@ void gfxQueueFSyncInit(gfxQueueFSync *pqueue);
* @param[in] ms The maxmimum time to wait for an item. For ASync queues this parameter is * @param[in] ms The maxmimum time to wait for an item. For ASync queues this parameter is
* not specified as TIME_IMMEDIATE is assumed. * not specified as TIME_IMMEDIATE is assumed.
* *
* @note The routines ending in "I" are interrupt/system/iclass level routines.
*
* @api * @api
* @{ * @{
*/ */
gfxQueueASyncItem *gfxQueueASyncGet(gfxQueueASync *pqueue); gfxQueueASyncItem *gfxQueueASyncGet(gfxQueueASync *pqueue);
gfxQueueASyncItem *gfxQueueASyncGetI(gfxQueueASync *pqueue);
gfxQueueGSyncItem *gfxQueueGSyncGet(gfxQueueGSync *pqueue, delaytime_t ms); gfxQueueGSyncItem *gfxQueueGSyncGet(gfxQueueGSync *pqueue, delaytime_t ms);
gfxQueueFSyncItem *gfxQueueFSyncGet(gfxQueueFSync *pqueue, delaytime_t ms); gfxQueueFSyncItem *gfxQueueFSyncGet(gfxQueueFSync *pqueue, delaytime_t ms);
/* @} */ /* @} */
@ -124,12 +127,15 @@ gfxQueueFSyncItem *gfxQueueFSyncGet(gfxQueueFSync *pqueue, delaytime_t ms);
* @note FSync: Use a delay time of TIME_IMMEDIATE if you don't want to wait until the * @note FSync: Use a delay time of TIME_IMMEDIATE if you don't want to wait until the
* item is removed from the queue. Note that even if the timeout occurs - the item * item is removed from the queue. Note that even if the timeout occurs - the item
* remains in the queue. * remains in the queue.
* @note The routines ending in "I" are interrupt/system/iclass level routines.
* *
* @api * @api
* @{ * @{
*/ */
void gfxQueueASyncPut(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem); void gfxQueueASyncPut(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem);
void gfxQueueASyncPutI(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem);
void gfxQueueGSyncPut(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem); void gfxQueueGSyncPut(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem);
void gfxQueueGSyncPutI(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem);
bool_t gfxQueueFSyncPut(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delaytime_t ms); bool_t gfxQueueFSyncPut(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delaytime_t ms);
/* @} */ /* @} */
@ -141,6 +147,7 @@ bool_t gfxQueueFSyncPut(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delayti
* @{ * @{
*/ */
#define gfxQueueASyncPop(pqueue) gfxQueueASyncGet(pqueue) #define gfxQueueASyncPop(pqueue) gfxQueueASyncGet(pqueue)
#define gfxQueueASyncPopI(pqueue) gfxQueueASyncGetI(pqueue)
#define gfxQueueGSyncPop(pqueue, ms) gfxQueueGSyncGet(pqueue, ms) #define gfxQueueGSyncPop(pqueue, ms) gfxQueueGSyncGet(pqueue, ms)
#define gfxQueueFSyncPop(pqueue, ms) gfxQueueFSyncGet(pqueue, ms) #define gfxQueueFSyncPop(pqueue, ms) gfxQueueFSyncGet(pqueue, ms)
/* @} */ /* @} */
@ -156,12 +163,15 @@ bool_t gfxQueueFSyncPut(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delayti
* @note FSync: Use a delay time of TIME_IMMEDIATE if you don't want to wait until the * @note FSync: Use a delay time of TIME_IMMEDIATE if you don't want to wait until the
* item is removed from the queue. Note that even if the timeout occurs - the item * item is removed from the queue. Note that even if the timeout occurs - the item
* remains in the queue. * remains in the queue.
* @note The routines ending in "I" are interrupt/system/iclass level routines.
* *
* @api * @api
* @{ * @{
*/ */
void gfxQueueASyncPush(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem); void gfxQueueASyncPush(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem);
void gfxQueueASyncPushI(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem);
void gfxQueueGSyncPush(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem); void gfxQueueGSyncPush(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem);
void gfxQueueGSyncPushI(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem);
bool_t gfxQueueFSyncPush(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delaytime_t ms); bool_t gfxQueueFSyncPush(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delaytime_t ms);
/* @} */ /* @} */
@ -175,12 +185,15 @@ bool_t gfxQueueFSyncPush(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delayt
* @note If the item isn't in the queue the routine just returns. * @note If the item isn't in the queue the routine just returns.
* @note If a process is waiting on the Put/Push operation for the item, that process * @note If a process is waiting on the Put/Push operation for the item, that process
* will be signaled. * will be signaled.
* @note The routines ending in "I" are interrupt/system/iclass level routines.
* *
* @api * @api
* @{ * @{
*/ */
void gfxQueueASyncRemove(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem); void gfxQueueASyncRemove(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem);
void gfxQueueASyncRemoveI(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem);
void gfxQueueGSyncRemove(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem); void gfxQueueGSyncRemove(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem);
void gfxQueueGSyncRemoveI(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem);
void gfxQueueFSyncRemove(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem); void gfxQueueFSyncRemove(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem);
/* @} */ /* @} */
@ -190,12 +203,17 @@ void gfxQueueFSyncRemove(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem);
* *
* @param[in] pqueue A pointer to the queue * @param[in] pqueue A pointer to the queue
* *
* @note The routines ending in "I" are interrupt/system/iclass level routines.
*
* @api * @api
* @{ * @{
*/ */
bool_t gfxQueueASyncIsEmpty(gfxQueueASync *pqueue); #define gfxQueueASyncIsEmpty(pqueue) (pqueue->head == 0)
bool_t gfxQueueGSyncIsEmpty(gfxQueueGSync *pqueue); #define gfxQueueASyncIsEmptyI(pqueue) (pqueue->head == 0)
bool_t gfxQueueFSyncIsEmpty(gfxQueueFSync *pqueue); #define gfxQueueGSyncIsEmpty(pqueue) (pqueue->head == 0)
#define gfxQueueGSyncIsEmptyI(pqueue) (pqueue->head == 0)
#define gfxQueueFSyncIsEmpty(pqueue) (pqueue->head == 0)
#define gfxQueueFSyncIsEmptyI(pqueue) (pqueue->head == 0)
/* @} */ /* @} */
/** /**
@ -206,13 +224,17 @@ bool_t gfxQueueFSyncIsEmpty(gfxQueueFSync *pqueue);
* @param[in] pitem A pointer to the queue item * @param[in] pitem A pointer to the queue item
* *
* @note This operation may be expensive. * @note This operation may be expensive.
* @note The routines ending in "I" are interrupt/system/iclass level routines.
* *
* @api * @api
* @{ * @{
*/ */
bool_t gfxQueueASyncIsIn(gfxQueueASync *pqueue, const gfxQueueASyncItem *pitem); bool_t gfxQueueASyncIsIn(gfxQueueASync *pqueue, const gfxQueueASyncItem *pitem);
bool_t gfxQueueASyncIsInI(gfxQueueASync *pqueue, const gfxQueueASyncItem *pitem);
bool_t gfxQueueGSyncIsIn(gfxQueueGSync *pqueue, const gfxQueueGSyncItem *pitem); bool_t gfxQueueGSyncIsIn(gfxQueueGSync *pqueue, const gfxQueueGSyncItem *pitem);
bool_t gfxQueueGSyncIsInI(gfxQueueGSync *pqueue, const gfxQueueGSyncItem *pitem);
bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem); bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem);
bool_t gfxQueueFSyncIsInI(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem);
/* @} */ /* @} */
/** /**
@ -226,13 +248,17 @@ bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem);
* @note As that item is still on the queue, it should be treated as read-only. It could * @note As that item is still on the queue, it should be treated as read-only. It could
* also be removed from the queue at any time by another thread (thereby altering the * also be removed from the queue at any time by another thread (thereby altering the
* queue item). * queue item).
* @note The routines ending in "I" are interrupt/system/iclass level routines.
* *
* @api * @api
* @{ * @{
*/ */
#define gfxQueueASyncPeek(pqueue) ((const gfxQueueASyncItem *)((pqueue)->head)) #define gfxQueueASyncPeek(pqueue) ((const gfxQueueASyncItem *)((pqueue)->head))
#define gfxQueueASyncPeekI(pqueue) ((const gfxQueueASyncItem *)((pqueue)->head))
#define gfxQueueGSyncPeek(pqueue) ((const gfxQueueGSyncItem *)((pqueue)->head)) #define gfxQueueGSyncPeek(pqueue) ((const gfxQueueGSyncItem *)((pqueue)->head))
#define gfxQueueGSyncPeekI(pqueue) ((const gfxQueueGSyncItem *)((pqueue)->head))
#define gfxQueueFSyncPeek(pqueue) ((const gfxQueueFSyncItem *)((pqueue)->head)) #define gfxQueueFSyncPeek(pqueue) ((const gfxQueueFSyncItem *)((pqueue)->head))
#define gfxQueueFSyncPeekI(pqueue) ((const gfxQueueFSyncItem *)((pqueue)->head))
/* @} */ /* @} */
/** /**
@ -246,13 +272,17 @@ bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem);
* @note As that item is still on the queue, it should be treated as read-only. It could * @note As that item is still on the queue, it should be treated as read-only. It could
* also be removed from the queue at any time by another thread (thereby altering the * also be removed from the queue at any time by another thread (thereby altering the
* queue item). * queue item).
* @note The routines ending in "I" are interrupt/system/iclass level routines.
* *
* @api * @api
* @{ * @{
*/ */
#define gfxQueueASyncNext(pitem) ((const gfxQueueASyncItem *)((pitem)->next)) #define gfxQueueASyncNext(pitem) ((const gfxQueueASyncItem *)((pitem)->next))
#define gfxQueueASyncNextI(pitem) ((const gfxQueueASyncItem *)((pitem)->next))
#define gfxQueueGSyncNext(pitem) ((const gfxQueueGSyncItem *)((pitem)->next)) #define gfxQueueGSyncNext(pitem) ((const gfxQueueGSyncItem *)((pitem)->next))
#define gfxQueueGSyncNextI(pitem) ((const gfxQueueGSyncItem *)((pitem)->next))
#define gfxQueueFSyncNext(pitem) ((const gfxQueueFSyncItem *)((pitem)->next)) #define gfxQueueFSyncNext(pitem) ((const gfxQueueFSyncItem *)((pitem)->next))
#define gfxQueueFSyncNextI(pitem) ((const gfxQueueFSyncItem *)((pitem)->next))
/* @} */ /* @} */
#ifdef __cplusplus #ifdef __cplusplus