Mercurial > hg > Members > innparusu > Gears
view src/synchronizedQueue/synchronizedQueue.c @ 30:604135010c3a
Add file synchronizedQueue.c
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 01 May 2015 18:26:05 +0900 |
parents | |
children | 240c045ebab2 |
line wrap: on
line source
#include "synchronizedQueueContext.h" #include "origin_cs.h" #ifdef CLANG #define _CbC_retrun __return #define _CbC_environment __environment #endif #define NUM 100 #define ALLOCATE_SIZE 1000000000 extern __code initSynchronizedQueueContext(struct Context* context); static int num; __code code1(struct Context* context) { context->data[Allocate]->allocate.size = sizeof(long); context->data[Allocate]->allocate.next = Code2; goto meta(context, Allocator); } __code meta(struct Context* context, enum Code next) { goto (context->code[next])(context); } __code code2(struct Context* context) { context->data[1]->count = 0; goto meta(context, Code3); } __code code3(struct Context* context) { struct Allocate* allocate = &context->data[Allocate]->allocate; long loop = context->data[1]->count; if (loop == num) { goto meta(context, Code4); } allocate->size = sizeof(struct Node); allocate->after_put = Code3; context->data[1]->count++; goto meta(context, Put); } __code put(struct Context* context) { struct Allocate* allocate = &context->data[Allocate]->allocate; // sem_p pthread_mutext_lock(&allocate->queue_remain->mutex); while(sem->value == 0) { pthread_cond_wait(&allocate->queue_remain->cond, &allocate->queue_remain->mutex); } allocate->queue_remain->value--; pthread_mutext_unlock(&allocate->queue_remain->mutex); struct ListContext* list_context = context->data[Allocate]-> list_context; list_context->data[Allocate]->value = context->data[1]->count; // sem_v pthread_mutext_lock(&allocate->queue_count->mutex); allocate->queue_count->value++; pthare_cond_signal(&allocate->queue_count->cond); pthread_mutext_unlock(&allocate->queue_count->mutex); goto metaPut(context, ); } __code metaPut(struct Context* context, enum Code next){ } __code take(struct Context* context) { } __code cas(struct Context* context, enum Code next) { } int main(int argc, char const* argv[]) { num = (int)atoi(argv[1]); struct Context* context = (struct Context*)malloc(sizeof(struct Context); context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); context->data = malloc(sizeof(union Data**)*ALLOCATE_SIZE); context->heap = malloc(sizeof(union Data*)*ALLOCATE_SIZE); initSynchronizedQueueContext(context); goto start_code(context, Code1); }