37#include "tinycthread/tinycthread.h"
43#define SCIPtnyInitLock(lock) ( mtx_init((lock), mtx_plain) == thrd_success ? SCIP_OKAY : SCIP_ERROR )
44#define SCIPtnyDestroyLock(lock) ( mtx_destroy(lock) )
45#define SCIPtnyAcquireLock(lock) ( mtx_lock(lock) == thrd_success ? SCIP_OKAY : SCIP_ERROR )
46#define SCIPtnyReleaseLock(lock) ( mtx_unlock(lock) == thrd_success ? SCIP_OKAY : SCIP_ERROR )
49#define SCIPtnyInitCondition(condition) ( cnd_init(condition) == thrd_success ? SCIP_OKAY : SCIP_ERROR )
50#define SCIPtnyDestroyCondition(condition) ( cnd_destroy(condition) )
51#define SCIPtnySignalCondition(condition) ( cnd_signal(condition) == thrd_success ? SCIP_OKAY : SCIP_ERROR )
52#define SCIPtnyBroadcastCondition(condition) ( cnd_broadcast(condition) == thrd_success ? SCIP_OKAY : SCIP_ERROR )
53#define SCIPtnyWaitCondition(condition, lock) ( cnd_wait((condition), (lock)) == thrd_success ? SCIP_OKAY: SCIP_ERROR )
70_Thread_local
int _threadnumber;
130 _threadnumber = (int)(uintptr_t) threadnum;
209 while( currjob != newjob )
262 SCIP_Bool blockwhenfull
272 (*thrdpool)->currentid = 0;
273 (*thrdpool)->queuesize = qsize;
274 (*thrdpool)->nthreads = nthreads;
275 (*thrdpool)->blockwhenfull = blockwhenfull;
276 (*thrdpool)->shutdown =
FALSE;
277 (*thrdpool)->queueopen =
TRUE;
281 (*thrdpool)->jobqueue->firstjob =
NULL;
282 (*thrdpool)->jobqueue->lastjob =
NULL;
283 (*thrdpool)->jobqueue->njobs = 0;
287 (*thrdpool)->currentjobs->firstjob =
NULL;
288 (*thrdpool)->currentjobs->lastjob =
NULL;
289 (*thrdpool)->currentjobs->njobs = 0;
293 (*thrdpool)->finishedjobs->firstjob =
NULL;
294 (*thrdpool)->finishedjobs->lastjob =
NULL;
295 (*thrdpool)->finishedjobs->njobs = 0;
307 (*thrdpool)->currworkingthreads = 0;
313 for(
i = 0;
i < (unsigned)nthreads;
i++ )
315 if( thrd_create(&((*thrdpool)->threads[
i]),
threadPoolThread, (
void*)
i) != thrd_success )
319 _threadnumber = nthreads;
450 SCIP_Bool finishjobs,
451 SCIP_Bool completequeue
463 if( !(*thrdpool)->queueopen || (*thrdpool)->shutdown )
471 (*thrdpool)->queueopen =
FALSE;
476 while( (*thrdpool)->jobqueue->njobs > 0 )
483 (*thrdpool)->shutdown =
TRUE;
496 for(
i = 0;
i < (*thrdpool)->nthreads;
i++ )
500 if( thrd_join((*thrdpool)->threads[
i], &thrdretcode) != thrd_success )
510 assert((*thrdpool)->currentjobs->njobs == 0);
512 assert((*thrdpool)->finishedjobs->njobs == 0);
542 if( currjob !=
NULL )
544 while( currjob != jobqueue->
lastjob )
546 if( currjob->
jobid == jobid )
552 if( currjob->
jobid == jobid )
584 SCIP_Bool blockwhenfull
614 (*job)->jobid = jobid;
615 (*job)->jobfunc = jobfunc;
616 (*job)->args = jobarg;
617 (*job)->nextjob =
NULL;
677 if( currjob->
jobid == jobid )
734 if( mtx_init(&(*lock)->lock, mtx_plain) == thrd_success )
750 mtx_destroy(&(*lock)->lock);
759 if( mtx_lock(&lock->
lock) == thrd_success )
769 if( mtx_unlock(&lock->
lock) == thrd_success )
788 if( cnd_init(&(*condition)->condition) == thrd_success )
798 cnd_destroy(&(*condition)->condition);
807 if( cnd_signal(&condition->
condition) == thrd_success )
818 if( cnd_broadcast(&condition->
condition) == thrd_success )
831 if( cnd_wait(&condition->
condition, &lock->
lock) == thrd_success )
841 return _threadnumber;
#define SCIP_CALL_ABORT(x)
assert(minobj< SCIPgetCutoffbound(scip))
memory allocation routines
#define BMSfreeMemory(ptr)
#define BMSallocMemoryArray(ptr, num)
#define BMSfreeMemoryArray(ptr)
#define BMSallocMemory(ptr)
public methods for message output
struct SCIP_Job * nextjob
SCIP_RETCODE(* jobfunc)(void *args)
SCIP_JOBQUEUE * currentjobs
SCIP_JOBQUEUE * finishedjobs
the type definitions for the SCIP parallel interface
static SCIP_RETCODE freeJobQueue(void)
static SCIP_RETCODE threadPoolAddWork(SCIP_JOB *newjob, SCIP_SUBMITSTATUS *status)
static SCIP_JOBSTATUS checkJobQueue(SCIP_JOBQUEUE *jobqueue, int jobid)
SCIP_RETCODE SCIPtpiWaitCondition(SCIP_CONDITION *condition, SCIP_LOCK *lock)
SCIP_RETCODE SCIPtpiCreateJob(SCIP_JOB **job, int jobid, SCIP_RETCODE(*jobfunc)(void *args), void *jobarg)
static SCIP_RETCODE threadPoolThreadRetcode(void *threadnum)
SCIP_RETCODE SCIPtpiSignalCondition(SCIP_CONDITION *condition)
SCIP_RETCODE SCIPtpiAcquireLock(SCIP_LOCK *lock)
#define SCIPtnyInitCondition(condition)
static SCIP_RETCODE createThreadPool(SCIP_THREADPOOL **thrdpool, int nthreads, int qsize, SCIP_Bool blockwhenfull)
static void jobQueueAddJob(SCIP_THREADPOOL *threadpool, SCIP_JOB *newjob)
SCIP_RETCODE SCIPtpiExit(void)
#define SCIPtnyInitLock(lock)
SCIP_RETCODE SCIPtpiBroadcastCondition(SCIP_CONDITION *condition)
#define SCIPtnyBroadcastCondition(condition)
SCIP_RETCODE SCIPtpiSubmitJob(SCIP_JOB *job, SCIP_SUBMITSTATUS *status)
static SCIP_Bool isJobRunning(SCIP_JOBQUEUE *currentjobs, int jobid)
void SCIPtpiDestroyLock(SCIP_LOCK **lock)
SCIP_RETCODE SCIPtpiCollectJobs(int jobid)
#define SCIPtnyWaitCondition(condition, lock)
#define SCIPtnyReleaseLock(lock)
#define SCIPtnyDestroyCondition(condition)
#define SCIPtnySignalCondition(condition)
int SCIPtpiGetThreadNum(void)
int SCIPtpiGetNumThreads(void)
void SCIPtpiDestroyCondition(SCIP_CONDITION **condition)
int SCIPtpiGetNewJobID(void)
#define SCIPtnyDestroyLock(lock)
static int threadPoolThread(void *threadnum)
SCIP_RETCODE SCIPtpiInitLock(SCIP_LOCK **lock)
static SCIP_RETCODE freeThreadPool(SCIP_THREADPOOL **thrdpool, SCIP_Bool finishjobs, SCIP_Bool completequeue)
SCIP_RETCODE SCIPtpiReleaseLock(SCIP_LOCK *lock)
SCIP_RETCODE SCIPtpiInitCondition(SCIP_CONDITION **condition)
#define SCIPtnyAcquireLock(lock)
SCIP_RETCODE SCIPtpiInit(int nthreads, int queuesize, SCIP_Bool blockwhenfull)
enum SCIP_Retcode SCIP_RETCODE
enum SCIP_Submitstatus SCIP_SUBMITSTATUS
enum SCIP_Jobstatus SCIP_JOBSTATUS
@ SCIP_SUBMIT_QUEUECLOSED