34 typedef int ut_thread_id_t;
35 #elif defined(USE_PTHREADS)
38 typedef pthread_t ut_thread_id_t;
40 #error Unsupported Platform for UT_Thread
43 #define UT_INVALID_THREAD_ID ((ut_thread_id_t)0)
46 #define UT_THREAD_DEFAULT_STACK_SIZE (8U*1024U*1024U)
47 #define UT_THREAD_SMALL_STACK_SIZE (1U*1024U*1024U)
49 typedef void *(*UTthreadFunc)(
void*);
89 static UT_Thread *allocThread(SpinMode spin_mode,
bool uses_tbb=
true);
91 static int getNumProcessors();
94 static int activeThreadCount();
100 static void resetNumProcessors();
103 #if defined(USE_PTHREADS)
104 static ut_thread_id_t getMyThreadId() {
return pthread_self(); }
106 static ut_thread_id_t getMyThreadId();
109 static ut_thread_id_t getMainThreadId();
110 static int getMainSequentialThreadId();
113 return getMyThreadId() == getMainThreadId();
119 static bool isUTThreadCurrent();
126 static bool isThreadingEnabled();
132 static bool setThreadingEnabled(
bool will_be_enabled);
138 : myPreviouslyEnabled(setThreadingEnabled(false))
142 if (myPreviouslyEnabled)
143 setThreadingEnabled(
true);
146 const bool myPreviouslyEnabled;
152 for(
uint i = 0; i < cycles; i++)
153 #
if defined(USE_PTHREADS)
154 __asm__ __volatile__(
"pause;");
160 #if defined(USE_PTHREADS)
161 static inline void yield(
bool higher_only=
false)
172 struct timespec ts = {0,100};
177 static void yield(
bool higher_only=
false);
193 static void configureMaxThreads(
int maxthreads = 0);
200 static void configureThreadStackSize(
int stacksize);
203 static bool isMaxThreadsConfigured();
210 using TerminateFunc =
void (*)();
211 static TerminateFunc getTaskSchedulerExitCallback();
224 virtual void threadStarted();
228 virtual void threadEnded();
236 virtual int isResourceHog()
const;
239 virtual State getState();
241 virtual void waitForState(
State desired) = 0;
242 virtual void setSpinMode(
SpinMode spin_mode);
245 virtual void killThread() = 0;
249 virtual int niceThread(
int priority) = 0;
250 virtual int suspendThread() = 0;
251 virtual int restartThread() = 0;
254 {
return waitThread(0); }
257 virtual int64 getMemoryUsage(
bool inclusive)
const = 0;
264 virtual int waitThread(
int block=1) = 0;
267 virtual int isValid();
272 static void *threadWrapper(
void *
data);
275 virtual void setState(
State state) = 0;
297 int stacksize)
override;
308 int64 mem = inclusive ?
sizeof(*this) : 0;
322 UT_ThreadSet(
int nthreads=-1,
int null_thread_if_1_cpu = 0);
331 myUserData = user_data_array;
332 myUserDataInc = structlen;
336 myUserData = user_data;
342 int wait(
int block=1);
349 return myThreads[which];
387 UT_Thread *nextThread(
int *thread_index =0,
388 AssignmentStyle style = BLOCKING);
392 int wait(
int block = 1);
396 void cleanup(
int kill = 0);
402 return myThreads[
index];
406 void addThreads(
int thread_count);
418 static const uint cycles_for_noop = 4;
419 static const uint cycles_for_pause = cycles_for_noop * 4;
420 static const uint cycles_for_yield_higher = cycles_for_pause * 2;
421 static const uint cycles_for_yield_all = cycles_for_yield_higher * 2;
426 if (myCycles > cycles_for_yield_all)
433 if (myCycles <= cycles_for_noop)
437 else if (myCycles <= cycles_for_pause)
441 else if (myCycles <= cycles_for_yield_higher)
445 myCycles += (myCycles+1)>>1;
int getNumThreads() const
void setUserData(void *user_data)
#define SYS_DEPRECATED(__V__)
int64 getMemoryUsage(bool inclusive) const override
NOTE: This level doesn't own any data apart from itself.
virtual int restartThread()=0
void *(* UTthreadFunc)(void *)
UT_Thread * operator[](int index)
UT_Thread * operator[](int which)
virtual void setState(State state)=0
GLint GLenum GLsizei GLint GLsizei const void * data
virtual void waitForState(State desired)=0
void setFunc(UTthreadFunc func)
virtual bool startThread(UTthreadFunc func, void *data, int stacksize)=0
virtual void killThread()=0
const UT_TaskScope * myTaskScope
virtual int suspendThread()=0
virtual int niceThread(int priority)=0
static int isMainThread()
~ThreadingDisabledScope()
static void pause(uint cycles)
static void yield(bool higher_only=false)
virtual int waitThread(int block=1)=0
void setUserData(void *user_data_array, size_t structlen)