diff src/synchronizedQueue/synchronizedQueueContext.c @ 36:240c045ebab2

Add normal queue
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Fri, 15 May 2015 19:17:23 +0900
parents 5d9f74220506
children ce9fde200f3e
line wrap: on
line diff
--- a/src/synchronizedQueue/synchronizedQueueContext.c	Tue May 05 21:16:04 2015 +0900
+++ b/src/synchronizedQueue/synchronizedQueueContext.c	Fri May 15 19:17:23 2015 +0900
@@ -1,31 +1,46 @@
+#include <stdlib.h>
+
 #include "synchronizedQueueContext.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 meta(struct Context*);
 extern __code allocate(struct Context*);
 extern __code put(struct Context*);
-extern __code take(struct Context*);
+extern __code traverse(struct Context*);
+extern __code get(struct Context*);
 extern __code exit_code(struct Context*);
 
 __code initSynchronizedQueueContext(struct Context* context) {
-    context->codeSize = 3;
+    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[Allocator] = allocate;
     context->code[Put]       = put;
-    context->code[Take]      = take;
+    context->code[Traverse]  = traverse;
+    context->code[Get]       = get;
     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);
+
+    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->dataNum = Queue;
 }
-
-__code initListContext(struct ListContext* context) {
-    context->data     = malloc(sizeof(union ListData **)*ALLOCATE);
-    context->heap     = malloc(sizeof(union ListData *)*ALLOCATE);
-    context->dataSize = 0;
-}