Mercurial > hg > GearsTemplate
view src/parallel_execution/SingleLinkedQueue.cbc @ 269:5170539348ec
rename TaskManagerImpl.cbc
author | mir3636 |
---|---|
date | Sun, 29 Jan 2017 22:15:32 +0900 |
parents | ffcd80cc3a83 |
children | 68cf983475e7 |
line wrap: on
line source
#include "../context.h" #include "../origin_cs.h" #include <stdio.h> Queue* createSingleLinkedQueue(struct Context* context) { struct Queue* queue = new Stack(); struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue(); queue->queue = (union Data*)singleLinkedQueue; singleLinkedQueue->top = NULL; singleLinkedQueue->last = NULL; queue->take = C_takeSingleLinkedQueue; queue->put = C_putSingleLinkedQueue; queue->isEmpty = C_isEmptySingleLinkedQueue; queue->clear = C_clearSingleLinkedQueue; return queue; } void printQueue1(union Data* data) { struct Node* node = &data->Element.data->Node; if (node == NULL) { printf("NULL"); } else { printf("key = %d ,", node->key); printQueue1((union Data*)data->Element.next); } } void printQueue(union Data* data) { printQueue1(data); printf("\n"); } __code clearSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...)) { queue->top = NULL; goto next(...); } __code putSingleLinkedQueue(struct SingleLinkedQueue* queue, union Data* data, __code next(...)) { Element* element = new Element(); element->next = NULL; element->data = data; if (queue->last) { Element* last = queue->last; last->next = element; queue->last = element; } else { queue->top = element; queue->last = element; } goto next(...); } __code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, _code next(union Data* data, ...)) { if (queue->top) { data = queue->top->data; queue->top = queue->top->next; } else { data = NULL; } goto next(data, ...); } __code isEmptySingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...), __code whenEmpty(...)) { if (queue->top) goto next(...); else goto whenEmpty(...); }