void Pop() { struct ELEMENT * queueNode = getElementFromLink( (union LINK *) LinkedListPop( &queueList )); struct ELEMENT * stackNode = getElementFromLink( (union LINK *) LinkedListPop( &stackList )); struct ELEMENT * atomicNode = getElementFromLink( (union LINK *) AtomicListPop( &atomicList)); struct ELEMENT * heapNode = getElementFromLink( (union LINK *) HeapPop( &heap )); if( queueNode != NULL ) printf("queue returned %d\n", queueNode->Data ); else printf("queue returned null\n"); if( stackNode != NULL ) printf("stack returned %d\n", stackNode->Data ); else printf("stack returned null\n"); if( atomicNode != NULL ) printf("atomic returned %d\n", atomicNode->Data ); else printf("atomic returned null\n"); if( heapNode != NULL ) printf("heap returned %d\n", heapNode->Data ); else printf("heap returned null\n"); }
int main(int argc, char* argv[] ) { int value = 0; LinkedListHandle* list = LinkedListNew(); DBG_ASSERT(list != C_NULL); DBG_ASSERT( LinkedListSize(list) == 0 ); LinkedListAppend(&value, list); DBG_ASSERT( LinkedListSize(list) == 1 ); LinkedListPrepend(&value, list); DBG_ASSERT( LinkedListSize(list) == 2 ); LinkedListPrepend(&value, list); DBG_ASSERT( LinkedListSize(list) == 3 ); LinkedListAppend(&value, list); DBG_ASSERT( LinkedListSize(list) == 4 ); LinkedListAppend(&value, list); DBG_ASSERT( LinkedListSize(list) == 5 ); LinkedListPop(list); DBG_ASSERT( LinkedListSize(list) == 4 ); LinkedListPop(list); DBG_ASSERT( LinkedListSize(list) == 3 ); LinkedListShift(list); DBG_ASSERT( LinkedListSize(list) == 2 ); LinkedListShift(list); DBG_ASSERT( LinkedListSize(list) == 1 ); LinkedListDelete(list); return 0; }
struct WORKER_ITEM * WorkerGetItem( struct WORKER_QUEUE * queue ) { struct LINKED_LIST_LINK * link; //Note: This is safe because WorkerGetItem is only called in a thread //context. SemaphoreDown( & queue->Lock, NULL ); CritInterruptDisable(); link = LinkedListPop( & queue->List ); CritInterruptEnable(); ASSERT( link != NULL ); return BASE_OBJECT( link, struct WORKER_ITEM, Link ); }