38 typedef int ut_thread_id_t;
39 #elif defined(USE_PTHREADS)
42 typedef pthread_t ut_thread_id_t;
44 #error Unsupported Platform for UT_Thread
47 #define UT_INVALID_THREAD_ID ((ut_thread_id_t)0)
50 #define UT_THREAD_DEFAULT_STACK_SIZE (8U*1024U*1024U)
51 #define UT_THREAD_SMALL_STACK_SIZE (1U*1024U*1024U)
53 typedef void *(*UTthreadFunc)(
void*);
94 static UT_Thread *allocThread(SpinMode spin_mode);
96 static int getNumProcessors();
99 static int activeThreadCount();
105 static void resetNumProcessors();
108 #if defined(USE_PTHREADS)
109 static ut_thread_id_t getMyThreadId() {
return pthread_self(); }
111 static ut_thread_id_t getMyThreadId();
114 static ut_thread_id_t getMainThreadId();
115 static int getMainSequentialThreadId();
118 return getMyThreadId() == getMainThreadId();
124 static bool isUTThreadCurrent();
131 static bool isThreadingEnabled();
137 static bool setThreadingEnabled(
bool will_be_enabled);
143 : myPreviouslyEnabled(setThreadingEnabled(false))
147 if (myPreviouslyEnabled)
148 setThreadingEnabled(
true);
151 const bool myPreviouslyEnabled;
157 for(
uint i = 0; i < cycles; i++)
158 #
if defined(USE_PTHREADS)
160 __asm__ __volatile__(
"yield;");
162 __asm__ __volatile__(
"pause;");
169 #if defined(USE_PTHREADS)
170 static inline void yield(
bool higher_only=
false)
181 struct timespec ts = {0,100};
186 static void yield(
bool higher_only=
false);
202 static void configureMaxThreads(
int maxthreads = 0);
209 static void configureThreadStackSize(
int stacksize);
212 static int getCurrentThreadStackSize();
218 static bool minimizeThisThreadPriority();
226 void setQoS(qos_class_t qos);
231 qos_class_t getQoS()
const;
255 virtual void threadStarted();
259 virtual void threadEnded();
267 virtual int isResourceHog()
const;
270 virtual State getState();
272 virtual void waitForState(
State desired) = 0;
273 virtual void setSpinMode(
SpinMode spin_mode);
276 virtual void killThread() = 0;
280 virtual int suspendThread() = 0;
281 virtual int restartThread() = 0;
284 {
return waitThread(0); }
287 virtual int64 getMemoryUsage(
bool inclusive)
const = 0;
294 virtual int waitThread(
int block=1) = 0;
297 virtual int isValid();
302 static void *threadWrapper(
void *
data);
324 static void onExit_();
339 int stacksize)
override;
349 int64 mem = inclusive ?
sizeof(*this) : 0;
363 UT_ThreadSet(
int nthreads=-1,
int null_thread_if_1_cpu = 0);
375 myUserData = user_data_array;
376 myUserDataInc = structlen;
380 myUserData = user_data;
386 int wait(
int block=1);
393 return myThreads[which];
434 UT_Thread *nextThread(
int *thread_index =0,
435 AssignmentStyle style = BLOCKING);
439 int wait(
int block = 1);
449 return myThreads[
index];
453 void addThreads(
int thread_count);
465 static const uint cycles_for_noop = 4;
466 static const uint cycles_for_pause = cycles_for_noop * 4;
467 static const uint cycles_for_yield_higher = cycles_for_pause * 2;
468 static const uint cycles_for_yield_all = cycles_for_yield_higher * 2;
473 if (myCycles > cycles_for_yield_all)
480 if (myCycles <= cycles_for_noop)
484 else if (myCycles <= cycles_for_pause)
488 else if (myCycles <= cycles_for_yield_higher)
492 myCycles += (myCycles+1)>>1;
525 template <
typename Func,
typename... Args>
528 WrapFunctor<Func, Args...>(std::forward<Func>(
func)),
529 std::forward<Args>(
args)...)
539 template <
typename Func,
typename... Args>
543 WrapFunctor(Func&&
func)
544 : myFunc(std::move(
func))
548 decltype(
auto) operator()(Args&&...
args)
const
551 return myFunc(std::forward<Args>(args)...);
568 myThreads.setSize(nthreads);
576 return myThreads(idx);
580 return myThreads(idx);
584 return myThreads[idx];
588 return myThreads[idx];
592 for (
auto&&
t : myThreads)
605 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
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)