diff src/parallel_execution/worker.c @ 230:a1fb3f2d1a36

fix worker
author ikkun
date Sat, 21 Jan 2017 20:21:00 +0900
parents 991f3d1ce072
children 123b0d277b84
line wrap: on
line diff
--- a/src/parallel_execution/worker.c	Sat Jan 21 20:04:32 2017 +0900
+++ b/src/parallel_execution/worker.c	Sat Jan 21 20:21:00 2017 +0900
@@ -3,60 +3,38 @@
 #include "context.h"
 #include "origin_cs.h"
 
-union Data* createWorker(struct Context* context) {
+union Data* createWorker(struct Context* context, int id, Queue* queue) {
     struct Worker* worker = &ALLOCATE(context, Worker)->Worker;
-    worker->execute = C_executeWorker;
-    worker->taskSend = C_taskSendWorker;
+    worker->tasks = queue;
+    worker->id = id;
+    worker->runFlag = 1;
     worker->taskReceive = C_taskReceiveWorker;
     worker->shutdown = C_shutdownWorker;
     return (union Data*)(worker);
 }
 
-__code taskSendWorker(struct Context* context) {
-}
-
-__code taskSendWorker_stub(struct Context* context) {
-    goto taskSendWorker(context);
-}
-
-__code executeWorker(struct Context* context, Worker* worker) {
-    worker->next = worker->taskReceive;
-    goto meta(context, task->code);
-}
-
-__code executeWorker_stub(struct Context* context) {
-    Worker* worker = &Gearef(context,Worker);
-    goto extcuteWorker(context,worker);
-}
-
 __code taskReceiveWorker(struct Context* context, Worker* worker) {
-    Queue* queue = &Gearef(context,queue);
-    queue->queue = worker->tasks;
+    if (! worker->runFlag)
+        goto meta(context, worker->next);
+    Queue* queue = worker->tasks;
     queue->next = C_getTask1;
     goto meta(context, queue->take);
 }
 
 __code taskReceiveWorker_stub(struct Context* context) {
-    Worker* worker = Gearef(context,Worker).worker;
-    goto taskReceiveWorker(context,queue);
+    Worker* worker = Gearef(context,Worker);
+    goto taskReceiveWorker(context,worker);
 }
 
-__code getTask1(struct Context* context, struct Queue* queue) {
-    queue->next = C_getTask2;
-    goto meta(context, queue->take);
+__code getTask1(struct Context* context, Worker* worker, struct Context* task) {
+    task->worker = worker;
+    goto meta(task, task->next);
 }
 
 __code getTask1_stub(struct Context* context) {
-    goto getTask1(context,/* &context->data[D_ActiveQueue]->Queue*/ NULL);
-}
-
-__code getTask2(struct Context* context, struct Task* task, struct Node* node) {
-    context->next = C_getTask1;
-    goto meta(context, C_getTask2);
-}
-
-__code getTask2_stub(struct Context* context) {
-    goto getTask2(context, /*&(context->data[D_ActiveQueue]->Queue.data->Task)*/ NULL, &context->data[D_Node]->Node);
+    Worker* worker = Gearef(context,Worker);
+    Context* task = &worker->tasks->data->context; 
+    goto getTask1(context,worker,task);
 }
 
 #ifdef USE_CUDA
@@ -67,6 +45,11 @@
 }
 #endif
 
-__code shutdownWorker(struct Context* context) {
+__code shutdownWorker(struct Context* context, Worker* worker) {
+    worker->runFlag = 0;
+}
 
+__code shutdownWorker_stub(struct Context* context) {
+    Worker* worker = Gearef(context,Worker);
+    goto shutdownWorker(context,worker);
 }