Mercurial > hg > Members > Moririn
view src/synchronizedQueue/synchronizedQueue.c @ 37:a1fc4c670150
Add CMakeLists.txt to synchronizedQueue
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 15 May 2015 19:19:31 +0900 |
parents | 240c045ebab2 |
children | ce9fde200f3e |
line wrap: on
line source
#include <stdlib.h> #include <stdio.h> #include "synchronizedQueueContext.h" #include "allocate.h" #include "origin_cs.h" extern __code initSynchronizedQueueContext(struct Context* context); __code code1(struct Context* context) { context->data[Allocate]->allocate.size = sizeof(struct Element); context->data[Allocate]->allocate.next = Code2; goto meta(context, Allocator); } __code meta(struct Context* context, enum Code next) { goto (context->code[next])(context); } __code meta_code2(struct Context* context, enum Code next) { context->data[Queue]->queue.head = context->data[context->dataNum]; context->data[Queue]->queue.tail = context->data[Queue]->queue.head; context->data[context->dataNum]->element.next = 0; goto (context->code[next])(context); } __code code2(struct Context* context) { context->data[context->dataNum] -> element.value = 1024; context->data[Allocate]->allocate.size = sizeof(struct Element); context->data[Allocate]->allocate.next = Code3; goto meta_code2(context, Allocator); } __code code3(struct Context* context) { context->data[Allocate]->allocate.after_put = Code4; context->data[context->dataNum] -> element.value = 10; goto meta(context, Put); } __code meta_put(struct Context* context, enum Code next) { context->data[Queue]->queue.tail->element.next = context->data[context->dataNum]; context->data[Queue]->queue.tail = context->data[Queue]->queue.tail->element.next; context->data[Queue]->queue.tail->element.next = 0; goto (context->code[next])(context); } __code put(struct Context* context) { goto meta_put(context, context->data[Allocate]->allocate.after_put); } __code meta_traverse(struct Context* context, enum Code next) { printf("current value in queue is %d\n", context->data[Queue]->queue.current->element.value); if (context->data[Queue]->queue.current->element.next) { context->data[Queue]->queue.current = context->data[Queue]->queue.current->element.next; goto meta_traverse(context, next); } goto (context->code[next])(context); } __code traverse(struct Context* context) { context->data[Queue]->queue.current = context->data[Queue]->queue.head; goto meta_traverse(context, context->data[Allocate]->allocate.after_traverse); } __code code4(struct Context* context) { context->data[Allocate]->allocate.after_traverse = Code5; goto meta(context, Traverse); } __code code5(struct Context* context) { context->data[Allocate]->allocate.after_get = Code6; goto meta(context, Get); } __code meta_get(struct Context* context, enum Code next) { if (context->data[Queue]->queue.head == context->data[Queue]->queue.tail) { printf("queue is empty\n"); goto (context->code[Exit])(context); } context->data[Queue]->queue.head = (context->data[Queue]->queue.head->element.next) ? context->data[Queue]->queue.head->element.next : 0; goto (context->code[next])(context); } __code get(struct Context* context) { goto meta_get(context, context->data[Allocate]->allocate.after_get); } __code code6(struct Context* context) { printf("after delete\n"); context->data[Allocate]->allocate.after_traverse = Exit; goto meta(context, Traverse); } int main() { struct Context* context = (struct Context*)malloc(sizeof(struct Context)); initSynchronizedQueueContext(context); goto start_code(context, Code1); }