annotate src/parallel_execution/context.h @ 304:9755206813cb

helper_string.h for ANSI C
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 14 Feb 2017 11:36:41 +0900
parents 8e7926f3e271
children ec0a5b4fba05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Context definition for llrb example */
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
2 #ifndef CONTEXT_H
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
3 #define CONTEXT_H
207
7470b8382672 Fix compile error to stack_test
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
4 #include <stdlib.h>
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <pthread.h>
304
9755206813cb helper_string.h for ANSI C
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 302
diff changeset
6 #ifdef USE_CUDAWorker
98
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
7 #include <cuda.h>
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 98
diff changeset
8 #endif
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
10 #define ALLOCATE_SIZE 20000000
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 98
diff changeset
11 #define NEW(type) (type*)(calloc(1, sizeof(type)))
8987cf13d5bb Add Allocate macro
innparusu
parents: 98
diff changeset
12 #define NEWN(n, type) (type*)(calloc(n, sizeof(type)))
8987cf13d5bb Add Allocate macro
innparusu
parents: 98
diff changeset
13
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
14 #define ALLOC_DATA(context, dseg) ({\
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
15 struct Meta* meta = (struct Meta*)context->heap;\
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 147
diff changeset
16 meta->type = D_##dseg;\
236
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
17 meta->size = 1;\
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
18 context->heap += sizeof(struct Meta);\
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 147
diff changeset
19 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[D_##dseg]; })
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 98
diff changeset
20
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
21 #define ALLOC_DATA_TYPE(context, dseg, t) ({\
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
22 struct Meta* meta = (struct Meta*)context->heap;\
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 147
diff changeset
23 meta->type = D_##t;\
236
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
24 meta->size = 1;\
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
25 context->heap += sizeof(struct Meta); \
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 147
diff changeset
26 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[D_##dseg]; })
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
28 #define ALLOCATE(context, t) ({ \
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
29 struct Meta* meta = (struct Meta*)context->heap;\
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
30 context->heap += sizeof(struct Meta);\
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
31 union Data* data = context->heap; \
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
32 context->heap += sizeof(struct t); \
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 147
diff changeset
33 meta->type = D_##t; \
236
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
34 meta->size = 1; \
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
35 data; })
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
36
233
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
37 #define ALLOC(context, t) (&ALLOCATE(context, t)->t)
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
38
237
mir3636
parents: 236
diff changeset
39 #define ALLOC_ARRAY(context, dseg, len) ({\
236
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
40 struct Meta* meta = (struct Meta*)context->heap;\
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
41 context->heap += sizeof(struct Meta);\
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
42 union Data* data = context->heap; \
244
d1567718f12c Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 242
diff changeset
43 context->heap += sizeof(struct dseg *)*len; \
236
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
44 meta->type = D_##dseg; \
237
mir3636
parents: 236
diff changeset
45 meta->size = len; \
236
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
46 data; })
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
47
288
f1b0cc555b6e Add odgCommit
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
48 #define GET_META(dseg) ((struct Meta*)(((void*)dseg) - sizeof(struct Meta)))
f1b0cc555b6e Add odgCommit
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
49 #define GET_TYPE(dseg) (GET_META(dseg)->type)
f1b0cc555b6e Add odgCommit
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
50 #define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait)
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
51
149
63ab65b28466 Add Gearef macro
one
parents: 148
diff changeset
52 #define Gearef(context, t) (&(context)->data[D_##t]->t)
186
dbc064c26b98 generate context script
mir3636
parents: 185
diff changeset
53
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
54 // (struct SingleLinkedStack *)context->data[D_Stack]->Stack.stack->Stack.stack
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
55
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
56 #define GearImpl(context, intf, name) (Gearef(context, intf)->name->intf.name)
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
57
186
dbc064c26b98 generate context script
mir3636
parents: 185
diff changeset
58 #include "c/enumCode.h"
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 enum Relational {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 EQ,
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 GT,
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 LT,
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 };
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
186
dbc064c26b98 generate context script
mir3636
parents: 185
diff changeset
66 #include "c/enumData.h"
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 struct Context {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 enum Code next;
230
a1fb3f2d1a36 fix worker
ikkun
parents: 222
diff changeset
70 struct Worker* worker;
a1fb3f2d1a36 fix worker
ikkun
parents: 222
diff changeset
71 struct TaskManager* taskManager;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 int codeNum;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 __code (**code) (struct Context*);
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 void* heapStart;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 void* heap;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 long heapLimit;
87
9e139a340bd1 rename directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
77 int dataNum;
236
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
78 int idgCount; //number of waiting dataGear
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 278
diff changeset
79 int odg;
288
f1b0cc555b6e Add odgCommit
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
80 int maxOdg;
242
9f3f8ed6ed9f Add sendTask
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 239
diff changeset
81 int workerId;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 union Data **data;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 };
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 union Data {
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
86 struct Meta {
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
87 enum DataType type;
236
865179a0a56d fix taskManager
ikkun
parents: 234
diff changeset
88 long size;
176
f0427e27dd7b create interface of Task, TaskManager, Worker
mir3636
parents: 172
diff changeset
89 struct Queue* wait; // tasks waiting this dataGear
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
90 } meta;
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 254
diff changeset
91 struct Context Context;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
92 struct Time {
102
64c98838a291 remove stack StartTime&EndTime
ikkun
parents: 101
diff changeset
93 enum Code next;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
94 double time;
149
63ab65b28466 Add Gearef macro
one
parents: 148
diff changeset
95 } Time;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 struct LoopCounter {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 int i;
166
mir3636
parents: 153
diff changeset
98 struct Tree* tree;
217
c34e6aa10967 Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 207
diff changeset
99 } LoopCounter;
176
f0427e27dd7b create interface of Task, TaskManager, Worker
mir3636
parents: 172
diff changeset
100 struct TaskManager {
218
d8a59b727f65 Fix spawnTaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
101 union Data* taskManager;
234
47588c28f189 TaskManager
mir3636
parents: 233
diff changeset
102 enum Code createTask; // create NEW contexts for execution & argument
47588c28f189 TaskManager
mir3636
parents: 233
diff changeset
103 enum Code spawn; // start NEW context on the worker
176
f0427e27dd7b create interface of Task, TaskManager, Worker
mir3636
parents: 172
diff changeset
104 enum Code shutdown;
233
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
105
184
mir3636
parents: 183
diff changeset
106 enum Code next;
233
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
107 enum Code task;
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
108 struct Context* context;
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
109 int worker;
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
110 int cpu;
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
111 int gpu;
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
112 int io;
237
mir3636
parents: 236
diff changeset
113 int maxCPU;
184
mir3636
parents: 183
diff changeset
114 } TaskManager;
182
57a11c15ff4c Add queue_test
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
115 struct TaskManagerImpl {
233
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
116 int numWorker;
242
9f3f8ed6ed9f Add sendTask
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 239
diff changeset
117 int sendWorkerIndex;
239
mir3636
parents: 237
diff changeset
118 pthread_mutex_t mutex;
184
mir3636
parents: 183
diff changeset
119 struct Queue* activeQueue;
mir3636
parents: 183
diff changeset
120 struct Queue* taskQueue;
244
d1567718f12c Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 242
diff changeset
121 struct Worker** workers;
184
mir3636
parents: 183
diff changeset
122 } TaskManagerImpl;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 struct Worker {
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
124 union Data* worker;
222
77faa28128b4 Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 218
diff changeset
125 enum Code taskReceive;
176
f0427e27dd7b create interface of Task, TaskManager, Worker
mir3636
parents: 172
diff changeset
126 enum Code shutdown;
230
a1fb3f2d1a36 fix worker
ikkun
parents: 222
diff changeset
127 enum Code next;
244
d1567718f12c Fix error
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 242
diff changeset
128 struct Queue* tasks;
288
f1b0cc555b6e Add odgCommit
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 287
diff changeset
129 struct TaskManager* taskManager;
184
mir3636
parents: 183
diff changeset
130 } Worker;
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
131 struct CPUWorker {
233
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
132 pthread_t thread;
242
9f3f8ed6ed9f Add sendTask
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 239
diff changeset
133 pthread_mutex_t mutex;
9f3f8ed6ed9f Add sendTask
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 239
diff changeset
134 pthread_cond_t cond;
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
135 struct Context* context;
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
136 int id;
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
137 } CPUWorker;
302
8e7926f3e271 fix CUDAWorker
ikkun
parents: 288
diff changeset
138 #ifdef USE_CUDAWorker
8e7926f3e271 fix CUDAWorker
ikkun
parents: 288
diff changeset
139 struct CUDAWorker {
233
06133afb3b5b create worker start_code
mir3636
parents: 232
diff changeset
140 pthread_t thread;
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
141 struct Context* context;
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
142 int id;
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
143 struct Queue* tasks;
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
144 int runFlag;
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
145 enum Code next;
98
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
146 CUdevice device;
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
147 CUcontext cuCtx;
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
148 CUfunction code;
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
149 CUdeviceptr* deviceptr;
d400948dbbab add Cuda infomation to context
ikkun
parents: 95
diff changeset
150 CUstream stream;
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
151 } CudaWorker;
187
bacc37265386 main.o fixed
mir3636
parents: 186
diff changeset
152 #else
302
8e7926f3e271 fix CUDAWorker
ikkun
parents: 288
diff changeset
153 struct CUDAWorker {
232
123b0d277b84 worker interface
mir3636
parents: 230
diff changeset
154 } CudaWorker;
101
8987cf13d5bb Add Allocate macro
innparusu
parents: 98
diff changeset
155 #endif
177
bb52f7f77bf5 add main
ikkun
parents: 176
diff changeset
156 struct Main {
bb52f7f77bf5 add main
ikkun
parents: 176
diff changeset
157 enum Code code;
bb52f7f77bf5 add main
ikkun
parents: 176
diff changeset
158 enum Code next;
bb52f7f77bf5 add main
ikkun
parents: 176
diff changeset
159 struct Queue* args;
185
247a2c4a8908 fix compile errors
mir3636
parents: 184
diff changeset
160 } Main;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
161 struct Task {
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
162 enum Code code;
176
f0427e27dd7b create interface of Task, TaskManager, Worker
mir3636
parents: 172
diff changeset
163 struct Queue* dataGears;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
164 int idsCount;
166
mir3636
parents: 153
diff changeset
165 } Task;
169
ea7b11f3e717 Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
166 // Queue Interface
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
167 struct Queue {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
168 union Data* queue;
167
34562e63981f create queue.c
mir3636
parents: 166
diff changeset
169 union Data* data;
34562e63981f create queue.c
mir3636
parents: 166
diff changeset
170 enum Code whenEmpty;
34562e63981f create queue.c
mir3636
parents: 166
diff changeset
171 enum Code clear;
34562e63981f create queue.c
mir3636
parents: 166
diff changeset
172 enum Code put;
34562e63981f create queue.c
mir3636
parents: 166
diff changeset
173 enum Code take;
34562e63981f create queue.c
mir3636
parents: 166
diff changeset
174 enum Code isEmpty;
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 124
diff changeset
175 enum Code next;
184
mir3636
parents: 183
diff changeset
176 } Queue;
167
34562e63981f create queue.c
mir3636
parents: 166
diff changeset
177 struct SingleLinkedQueue {
34562e63981f create queue.c
mir3636
parents: 166
diff changeset
178 struct Element* top;
34562e63981f create queue.c
mir3636
parents: 166
diff changeset
179 struct Element* last;
184
mir3636
parents: 183
diff changeset
180 } SingleLinkedQueue;
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 278
diff changeset
181 struct SynchronizedQueue {
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 278
diff changeset
182 struct Element* top;
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 278
diff changeset
183 struct Element* last;
287
6b099d73949c Add queueCount sem to SynchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 286
diff changeset
184 struct Semaphore* queueCount;
282
a3448b0f0a56 Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 278
diff changeset
185 } SynchronizedQueue;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
186 // Stack Interface
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 124
diff changeset
187 struct Stack {
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
188 union Data* stack;
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 124
diff changeset
189 union Data* data;
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
190 union Data* data1;
169
ea7b11f3e717 Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
191 enum Code whenEmpty;
145
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
192 enum Code clear;
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 124
diff changeset
193 enum Code push;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 124
diff changeset
194 enum Code pop;
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
195 enum Code pop2;
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 124
diff changeset
196 enum Code isEmpty;
134
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
197 enum Code get;
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
198 enum Code get2;
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 124
diff changeset
199 enum Code next;
194
081607dcf893 create generate_stub.pl
mir3636
parents: 187
diff changeset
200 } Stack;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
201 // Stack implementations
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
202 struct SingleLinkedStack {
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
203 struct Element* top;
194
081607dcf893 create generate_stub.pl
mir3636
parents: 187
diff changeset
204 } SingleLinkedStack;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
205 struct ArrayStack {
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
206 int size;
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
207 int limit;
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
208 struct Element* array;
194
081607dcf893 create generate_stub.pl
mir3636
parents: 187
diff changeset
209 } ArrayStack;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
210 // Stack implementation end
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
211 struct Element {
113
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
212 union Data* data;
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
213 struct Element* next;
194
081607dcf893 create generate_stub.pl
mir3636
parents: 187
diff changeset
214 } Element;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 struct Array {
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
216 int index;
95
3e28ee215c0e modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
217 int prefix;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 int* array;
194
081607dcf893 create generate_stub.pl
mir3636
parents: 187
diff changeset
219 } Array;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 struct Tree {
166
mir3636
parents: 153
diff changeset
221 union Data* tree;
mir3636
parents: 153
diff changeset
222 struct Node* node;
152
7164f59660d4 create .cbc
mir3636
parents: 149
diff changeset
223 enum Code put;
7164f59660d4 create .cbc
mir3636
parents: 149
diff changeset
224 enum Code get;
7164f59660d4 create .cbc
mir3636
parents: 149
diff changeset
225 enum Code remove;
171
747067fe46bd Fix selected Queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 170
diff changeset
226 enum Code clear;
152
7164f59660d4 create .cbc
mir3636
parents: 149
diff changeset
227 enum Code next;
166
mir3636
parents: 153
diff changeset
228 } Tree;
172
661b0b0d0399 replace Tree to RedBlackTree
ikkun
parents: 171
diff changeset
229 struct RedBlackTree {
152
7164f59660d4 create .cbc
mir3636
parents: 149
diff changeset
230 struct Node* root;
122
73a679a85c04 node stack rewrite
ikkun
parents: 119
diff changeset
231 struct Node* current; // reading node of original tree
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
232 struct Node* previous; // parent of reading node of original tree
124
36ac17d37be4 Fix compile error but not work
one
parents: 122
diff changeset
233 struct Node* newNode; // writing node of new tree
143
34a7a21edc36 recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
234 struct Node* parent;
34a7a21edc36 recude stack get using traverse field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
235 struct Node* grandparent;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
236 struct Stack* nodeStack;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 int result;
172
661b0b0d0399 replace Tree to RedBlackTree
ikkun
parents: 171
diff changeset
238 } RedBlackTree;
147
f2275f5777f4 add treeRotate data
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
239 struct RotateTree {
f2275f5777f4 add treeRotate data
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
240 enum Code next;
172
661b0b0d0399 replace Tree to RedBlackTree
ikkun
parents: 171
diff changeset
241 struct RedBlackTree* traverse;
147
f2275f5777f4 add treeRotate data
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
242 struct Tree* tree;
217
c34e6aa10967 Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 207
diff changeset
243 } RotateTree;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 struct Node {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 int key; // comparable data segment
90
4b5bf5b40970 put queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
246 union Data* value;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 struct Node* left;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 struct Node* right;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 // need to balancing
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 enum Color {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 Red,
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 Black,
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 } color;
217
c34e6aa10967 Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 207
diff changeset
254 } Node;
286
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
255 struct Semaphore {
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
256 union Data* semaphore;
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
257 enum Code p;
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
258 enum Code v;
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
259 enum Code next;
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
260 } Semaphore;
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
261 struct SemaphoreImpl {
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
262 int value;
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
263 pthread_mutex_t mutex;
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
264 pthread_cond_t cond;
fd470e090403 Add sempahore
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 282
diff changeset
265 } SemaphoreImpl;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 struct Allocate {
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 enum Code next;
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 long size;
217
c34e6aa10967 Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 207
diff changeset
269 } Allocate;
112
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
270 struct OutPutDataSegments {
e3cba827d489 Add spawnTask CS
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
271 union Data **data;
217
c34e6aa10967 Fix DataGear access name
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 207
diff changeset
272 } Ods;
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 244
diff changeset
273 }; // union Data end this is necessary for context generator
113
d05b9937aa95 Change element data from Task to Data
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
274
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 254
diff changeset
275 typedef union Data Data;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 254
diff changeset
276
186
dbc064c26b98 generate context script
mir3636
parents: 185
diff changeset
277 #include "c/typedefData.h"
278
23767f714f4a fix generate_stub
mir3636
parents: 259
diff changeset
278
23767f714f4a fix generate_stub
mir3636
parents: 259
diff changeset
279 #include "c/extern.h"
23767f714f4a fix generate_stub
mir3636
parents: 259
diff changeset
280
23767f714f4a fix generate_stub
mir3636
parents: 259
diff changeset
281 extern __code start_code(struct Context* context);
23767f714f4a fix generate_stub
mir3636
parents: 259
diff changeset
282 extern __code exit_code(struct Context* context);
23767f714f4a fix generate_stub
mir3636
parents: 259
diff changeset
283 extern __code meta(struct Context* context, enum Code next);
23767f714f4a fix generate_stub
mir3636
parents: 259
diff changeset
284 extern void initContext(struct Context* context);
23767f714f4a fix generate_stub
mir3636
parents: 259
diff changeset
285
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
286 #endif