# HG changeset patch # User Tatsuki IHA # Date 1430472277 -32400 # Node ID fa3038ae40adc0ea53f039ba4bb9105753d6d5e9 # Parent 44879c87c2dc0356172b3a81608d1490584961b1# Parent 5d9f74220506c41c2ce7e608624d67b31777e679 Merge diff -r 44879c87c2dc -r fa3038ae40ad src/synchronizedQueue/synchronizedQueueContext.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/synchronizedQueue/synchronizedQueueContext.c Fri May 01 18:24:37 2015 +0900 @@ -0,0 +1,31 @@ +#include "synchronizedQueueContext.h" + +extern __code code1(struct Context*); +extern __code code2(struct Context*); +extern __code code3(struct Context*); +extern __code meta(struct Context*); +extern __code allocate(struct Context*); +extern __code put(struct Context*); +extern __code take(struct Context*); +extern __code exit_code(struct Context*); + +__code initSynchronizedQueueContext(struct Context* context) { + context->codeSize = 3; + context->code[Code1] = code1; + context->code[Code2] = code2; + context->code[Code3] = code3; + context->code[Allocator] = allocate; + context->code[Put] = put; + context->code[Take] = take; + context->code[Exit] = exit_code; + context->dataSize = 0; + context->heap += sizeof(struct Allocate); + context->data[Allocate]->list_context = malloc(sizeof(union Data**)*ALLOCATE_SIZE); + initListContext(context->data[Allocate]->list_context); +} + +__code initListContext(struct ListContext* context) { + context->data = malloc(sizeof(union ListData **)*ALLOCATE); + context->heap = malloc(sizeof(union ListData *)*ALLOCATE); + context->dataSize = 0; +} diff -r 44879c87c2dc -r fa3038ae40ad src/synchronizedQueue/synchronizedQueueContext.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/synchronizedQueue/synchronizedQueueContext.h Fri May 01 18:24:37 2015 +0900 @@ -0,0 +1,61 @@ +/* Context definition for synchronized queue example */ + +#include + +enum Code { + Code1, + Code2, + Code3, + Allocator, + Put, + Take, + Exit, +}; + +enum UniqueData { + Allocate, +}; + +struct Context { + int codeSize; + __code (**code) (struct Context *); + void* heap; + int dataSize; + union Data **data; +}; + +struct Sem { + volatile int value; + pthread_mutex_t mutex; + pthread_cond_t cond; + +}; + +union Data { + long count; + struct ListContext { + int codeSize; + __code (**code) (struct Context *); + void* heap; + int dataSize; + struct ListData { + int value; + struct ListAllocate { + long size; + void* ds; + void* next; + } allocate; + } **data; + } *list_context; + + struct Allocate { + long size; + enum Code next; + enum Code after_put; + enum Code after_take; + struct Sem *queue_remain; + struct Sem *queue_count; + union Data* front; + union Data* back; + } allocate; +}