changeset 239:cc13a1608364

fix
author mir3636
date Tue, 24 Jan 2017 15:10:23 +0900
parents e450bd33b33b
children 9135e22799dd
files src/parallel_execution/context.h src/parallel_execution/taskManager.c
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/context.h	Tue Jan 24 09:21:47 2017 +0900
+++ b/src/parallel_execution/context.h	Tue Jan 24 15:10:23 2017 +0900
@@ -111,6 +111,7 @@
     } TaskManager;
     struct TaskManagerImpl {
         int numWorker;
+        pthread_mutex_t mutex;
         struct Queue* activeQueue;
         struct Queue* taskQueue;
         struct Worker* workers;
--- a/src/parallel_execution/taskManager.c	Tue Jan 24 09:21:47 2017 +0900
+++ b/src/parallel_execution/taskManager.c	Tue Jan 24 15:10:23 2017 +0900
@@ -33,18 +33,18 @@
     taskManagerImpl->workers = (Worker*)ALLOC_ARRAY(context,Worker,taskManager->maxCPU);
     for (;i>taskManager->gpu;i++) {
         Queue* queue = &createSynchronizedQueue(context)->Queue;
-        taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context,i,queue);
+        taskManagerImpl->workers[i] = *(Worker*)createCPUWorker(context,i,queue);
     }
     for (;i>taskManager->cpu;i++) {
 #ifdef USE_CUDA
 #else
         Queue* queue = &createSynchronizedQueue(context)->Queue;
-        taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context,i,queue);
+        taskManagerImpl->workers[i] = *(Worker*)createCPUWorker(context,i,queue);
 #endif        
     }
     for (;i>taskManager->maxCPU;i++) {
         Queue* queue = &createSynchronizedQueue(context)->Queue;
-        taskManagerImpl->workers[i] = (Worker*)createCPUWorker(context,i,queue);
+        taskManagerImpl->workers[i] = *(Worker*)createCPUWorker(context,i,queue);
     }
 }
 
@@ -68,27 +68,32 @@
     }
     queue->data = (union Data*)task;
     queue->next = next;
-    pthread_mutex_unlock(taskManagerImpl->mutex);
+    pthread_mutex_unlock(&taskManager->mutex);
     goto meta(context, queue->queue->Queue.put);
 }
 
 __code spawnTaskManager_stub(struct Context* context) {
-    pthread_mutex_lock(taskManager->mutex);
+    TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager);
+    pthread_mutex_lock(&taskManager->mutex);
     goto spawnTaskManager(context,
-                          (struct TaskManager*)GearImpl(context, TaskManager, taskManager),
+                          taskManager,
                           Gearef(context, Queue),
                           Gearef(context, TaskManager)->context,
                           Gearef(context, TaskManager)->next
             );
 }
 
-__code taskSend(struct Context* context) {
+__code taskSend(struct Context* context, TaskManagerImpl* taskManager) {
     if(loopCounter->i < taskManager->numWorker) {
         taskManager->workers[i]->taskSend;
         loopCounter->i++;
         goto meta(context, C_taskSend);
     }
-    goto meta(context, TaskManager->next);
+    goto meta(context, taskManager->next);
+}
+
+__code taskSend_stub(struct Context* context) {
+    goto taskSend(context, (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager));
 }
 
 __code createWorker1(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) {