Mercurial > hg > Gears > GearsAgda
view src/synchronizedQueue/synchronizedQueueForSemContext.c @ 143:34a7a21edc36
recude stack get using traverse field
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 09 Nov 2016 22:33:16 +0900 |
parents | 83ee9c75115a |
children |
line wrap: on
line source
#include <stdlib.h> #include "synchronizedQueueForSemContext.h" extern __code code1(struct Context*); extern __code code2(struct Context*); extern __code code3(struct Context*); extern __code code4(struct Context*); extern __code code5(struct Context*); extern __code code6(struct Context*); extern __code code7(struct Context*); extern __code meta(struct Context*); extern __code allocate(struct Context*); extern __code sender(struct Context*); extern __code put(struct Context*); extern __code receiver(struct Context*); extern __code get(struct Context*); extern __code exit_code(struct Context*); extern __code thread_exit(struct Context*); __code initSynchronizedQueueContext(struct Context* context) { context->dataSize = sizeof(union Data)*ALLOCATE_SIZE; context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); context->heap_start = malloc(context->dataSize); context->codeNum = Exit; context->code[Code1] = code1; context->code[Code2] = code2; context->code[Code3] = code3; context->code[Code4] = code4; context->code[Code5] = code5; context->code[Code6] = code6; context->code[Code7] = code7; context->code[Allocator] = allocate; context->code[Sender] = sender; context->code[Put] = put; context->code[Receiver] = receiver; context->code[Get] = get; context->code[Exit] = exit_code; context->code[ThreadExit] = thread_exit; context->heap = context->heap_start; context->data[Allocate] = context->heap; context->heap += sizeof(struct Allocate); context->data[Queue] = context->heap; context->heap += sizeof(struct Queue); context->data[Queue]->queue.first = 0; context->data[Queue]->queue.queue_remain = malloc(sizeof(struct Sem)); pthread_mutex_init(&context->data[Queue]->queue.queue_remain->mutex, NULL); pthread_cond_init(&context->data[Queue]->queue.queue_remain->cond, NULL); context->data[Queue]->queue.queue_remain->value = 10; context->data[Queue]->queue.queue_count = malloc(sizeof(struct Sem)); pthread_mutex_init(&context->data[Queue]->queue.queue_count->mutex, NULL); pthread_cond_init(&context->data[Queue]->queue.queue_count->cond, NULL); context->data[Queue]->queue.queue_count->value = 0; context->dataNum = Queue; }