void *WorkerThread(void *arg) { workerctx_t *wc = (workerctx_t *)arg; #ifdef HAVE___THREAD workerctx_cur = wc; #else /* HAVE___THREAD */ /* set pointer to worker context as TSD */ pthread_setspecific(workerctx_key, wc); #endif /* HAVE___THREAD */ //FIXME #ifdef USE_MCTX_PCL assert(0 == co_thread_init()); wc->mctx = co_current(); #endif wc->terminate = 0; wc->current_task = NULL; LpelThreadAssign(wc->wid + 1); // 0 is for the master WorkerLoop(wc); #ifdef USE_LOGGING /* cleanup monitoring */ if (wc->mon && MON_CB(worker_destroy)) { MON_CB(worker_destroy)(wc->mon); } #endif #ifdef USE_MCTX_PCL co_thread_cleanup(); #endif return NULL; }
/** * Thread function for workers (and wrappers) */ static void *WorkerThread( void *arg) { workerctx_t *wc = (workerctx_t *)arg; lpel_task_t *t; #ifdef HAVE___THREAD workerctx_cur = wc; #else /* HAVE___THREAD */ /* set pointer to worker context as TSD */ pthread_setspecific(workerctx_key, wc); #endif /* HAVE___THREAD */ #ifdef USE_MCTX_PCL int res = co_thread_init(); assert( 0 == res); wc->mctx = co_current(); #endif wc->current_task = NULL; /* no task marked for deletion */ wc->marked_del = NULL; /* assign to cores */ LpelThreadAssign( wc->wid); /*******************************************************/ if ( wc->wid >= 0) { WorkerLoop( wc); } else { WrapperLoop( wc); } /*******************************************************/ #ifdef USE_LOGGING /* cleanup monitoring */ if (wc->mon && MON_CB(worker_destroy)) { MON_CB(worker_destroy)(wc->mon); } #endif /* destroy all the free tasks */ while ((t = LpelPopTask(free, &wc->free_tasks))) { LpelTaskDestroy(t); } /* on a wrapper, we also can cleanup more*/ if (wc->wid < 0) { /* clean up the mailbox for the worker */ LpelMailboxDestroy(wc->mailbox); /* free the worker context */ free( wc); } #ifdef USE_MCTX_PCL co_thread_cleanup(); #endif return NULL; }