39 typedef int ut_thread_id_t;
40 #elif defined(USE_PTHREADS)
43 typedef pthread_t ut_thread_id_t;
45 #error Unsupported Platform for UT_Thread
48 #define UT_INVALID_THREAD_ID ((ut_thread_id_t)0)
51 #define UT_THREAD_DEFAULT_STACK_SIZE (8U*1024U*1024U)
52 #define UT_THREAD_SMALL_STACK_SIZE (1U*1024U*1024U)
54 typedef void *(*UTthreadFunc)(
void*);
95 static UT_Thread *allocThread(SpinMode spin_mode);
97 static int getNumProcessors();
100 static int activeThreadCount();
106 static void resetNumProcessors();
109 #if defined(USE_PTHREADS)
110 static ut_thread_id_t getMyThreadId() {
return pthread_self(); }
112 static ut_thread_id_t getMyThreadId();
115 static ut_thread_id_t getMainThreadId();
116 static int getMainSequentialThreadId();
119 return getMyThreadId() == getMainThreadId();
125 static bool isUTThreadCurrent();
132 static bool isThreadingEnabled();
138 static bool setThreadingEnabled(
bool will_be_enabled);
144 : myPreviouslyEnabled(setThreadingEnabled(false))
148 if (myPreviouslyEnabled)
149 setThreadingEnabled(
true);
152 const bool myPreviouslyEnabled;
158 for(
uint i = 0; i < cycles; i++)
159 #
if defined(USE_PTHREADS)
161 __asm__ __volatile__(
"yield;");
163 __asm__ __volatile__(
"pause;");
170 #if defined(USE_PTHREADS)
171 static inline void yield(
bool higher_only=
false)
182 struct timespec ts = {0,100};
187 static void yield(
bool higher_only=
false);
203 static void configureMaxThreads(
int maxthreads = 0);
210 static void configureThreadStackSize(
int stacksize);
213 static int getCurrentThreadStackSize();
219 static bool minimizeThisThreadPriority();
227 void setQoS(qos_class_t qos);
232 qos_class_t getQoS()
const;
256 virtual void threadStarted();
260 virtual void threadEnded();
268 virtual int isResourceHog()
const;
271 virtual State getState();
273 virtual void waitForState(
State desired) = 0;
274 virtual void setSpinMode(
SpinMode spin_mode);
281 virtual void killThread() = 0;
285 virtual int suspendThread() = 0;
286 virtual int restartThread() = 0;
289 {
return waitThread(0); }
292 virtual int64 getMemoryUsage(
bool inclusive)
const = 0;
299 virtual int waitThread(
int block=1) = 0;
302 virtual int isValid();
307 static void *threadWrapper(
void *
data);
331 static void onExit_();
346 int stacksize)
override;
356 int64 mem = inclusive ?
sizeof(*this) : 0;
370 UT_ThreadSet(
int nthreads=-1,
int null_thread_if_1_cpu = 0);
382 myUserData = user_data_array;
383 myUserDataInc = structlen;
387 myUserData = user_data;
393 int wait(
int block=1);
400 return myThreads[which];
441 UT_Thread *nextThread(
int *thread_index =0,
442 AssignmentStyle style = BLOCKING);
446 int wait(
int block = 1);
456 return myThreads[
index];
460 void addThreads(
int thread_count);
472 static const uint cycles_for_noop = 4;
473 static const uint cycles_for_pause = cycles_for_noop * 4;
474 static const uint cycles_for_yield_higher = cycles_for_pause * 2;
475 static const uint cycles_for_yield_all = cycles_for_yield_higher * 2;
480 if (myCycles > cycles_for_yield_all)
487 if (myCycles <= cycles_for_noop)
491 else if (myCycles <= cycles_for_pause)
495 else if (myCycles <= cycles_for_yield_higher)
499 myCycles += (myCycles+1)>>1;
532 template <
typename Func,
typename... Args>
535 WrapFunctor<Func, Args...>(std::forward<Func>(
func)),
536 std::forward<Args>(
args)...)
546 template <
typename Func,
typename... Args>
550 WrapFunctor(Func&&
func)
551 : myFunc(std::move(
func))
555 decltype(
auto) operator()(Args&&...
args)
const
558 return myFunc(std::forward<Args>(args)...);
575 myThreads.setSize(nthreads);
583 return myThreads(idx);
587 return myThreads(idx);
591 return myThreads[idx];
595 return myThreads[idx];
599 for (
auto&&
t : myThreads)
612 for (
auto&&
t : myThreads)
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.
The subsystem to initialize and cleanup UT.
virtual int restartThread()=0
void *(* UTthreadFunc)(void *)
UT_StdThread(Func &&func, Args &&...args)
UT_Thread * operator[](int index)
bool joinable(int idx) const
UT_StdThread & operator=(const UT_StdThread &)=delete
UT_Thread * operator[](int which)
thread_t & operator[](int idx)
virtual void setState(State state)=0
UT_StdThreadGroup & operator=(const UT_StdThreadGroup &)=delete
static int getNumProcessors()
virtual void waitForState(State desired)=0
void setFunc(UTthreadFunc func)
virtual bool startThread(UTthreadFunc func, void *data, int stacksize)=0
UT_Thread & operator=(const UT_Thread &)=delete
virtual void killThread()=0
GLuint const GLchar * name
const UT_TaskScope * myTaskScope
const thread_t & operator[](int idx) const
FS_API bool cleanup(UT_StringArray &removed, UT_StringArray &error_files, exint &memory_freed, bool dry_run, const char *override_path=nullptr)
virtual int suspendThread()=0
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
static int isMainThread()
~ThreadingDisabledScope()
LeafData & operator=(const LeafData &)=delete
static void pause(uint cycles)
**If you just want to fire and args
static void yield(bool higher_only=false)
virtual int waitThread(int block=1)=0
void setUserData(void *user_data_array, size_t structlen)
UT_StdThreadGroup(int nthreads=-1)