changeset 28:5d9f74220506

Add file synchronizedQueueContext
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Fri, 01 May 2015 18:23:44 +0900
parents 06fcbe45e85c
children fa3038ae40ad
files src/synchronizedQueue/synchronizedQueueContext.c src/synchronizedQueue/synchronizedQueueContext.h
diffstat 2 files changed, 92 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/synchronizedQueue/synchronizedQueueContext.c	Fri May 01 18:23:44 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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/synchronizedQueue/synchronizedQueueContext.h	Fri May 01 18:23:44 2015 +0900
@@ -0,0 +1,61 @@
+/* Context definition for synchronized queue example */
+
+#include <pthread.h>
+
+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;
+}