void *queue_remove(struct queue *queue, void *data) { struct list *entry; if ( !queue->head ) return NULL; entry = list_find(queue->head, data); if ( NULL == entry ) { // We didnt find this entry return NULL; } // This entry is there in the list if ( queue->head == entry ) { // This is the first node data = queue_pop_head(queue); return data; } else if ( queue->tail == entry ) { // This is the tail node data = queue_pop_tail(queue); return data; } // This is and arbitary location, between head and tail queue->length--; __list_remove(entry, entry); __list_free(entry); return data; }
struct list *__queue_pop_tail(struct queue *queue) { struct list *entry = queue->tail; struct list *prev; if (entry) { prev = entry->prev; queue->head = __list_remove(queue->head, entry); queue->tail = prev; queue->length--; } return entry; }
struct list *__queue_pop_head(struct queue *queue) { struct list *entry = queue->head; if (entry) { queue->head = __list_remove(queue->head, entry); if (!queue->head) queue->tail = NULL; queue->length--; } return entry; }
static void unlock_mem_block (struct _LOCK_FOR_POOL * pstGlue, const char * pcName, struct _MEM_PTR * pstPtr, bool destroy) { struct _MEM_LOCK * pstLock = NULL; unsigned int index = 0; for (__list_start_iterator(pstGlue->stLockList.pData, 0); __list_has_next(pstGlue->stLockList.pData); pstLock = NULL) { pstLock = (struct _MEM_LOCK *)__list_next(pstGlue->stLockList.pData, NULL, &index); if (!strcmp(pstLock->pcName, pcName)) { break; } } // Remove the entry from the list first. Then close the handle. if (pstLock) { __semaphore_release(pstLock->pLockHandle); if (destroy) { __semaphore_destroy(pstLock->pLockHandle); __list_remove(pstGlue->stLockList.pData, index); } free(pstLock); } }