HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Thread Class Referenceabstract

#include <UT_Thread.h>

+ Inheritance diagram for UT_Thread:

Classes

class  DisableGlobalControl
 
class  ThreadingDisabledScope
 

Public Types

enum  State { ThreadIdle, ThreadRunning }
 
enum  SpinMode { ThreadSingleRun, ThreadLowUsage }
 

Public Member Functions

virtual ~UT_Thread ()
 
 UT_Thread (const UT_Thread &)=delete
 
UT_Threadoperator= (const UT_Thread &)=delete
 
virtual bool startThread (UTthreadFunc func, void *data, int stacksize)=0
 
bool startThread (UTthreadFunc func, void *data)
 
virtual void threadStarted ()
 
virtual void threadEnded ()
 
virtual int isResourceHog () const
 
virtual State getState ()
 
virtual SpinMode getSpinMode ()
 
virtual void waitForState (State desired)=0
 
virtual void setSpinMode (SpinMode spin_mode)
 
virtual void killThread ()=0
 
virtual int suspendThread ()=0
 
virtual int restartThread ()=0
 
int isActive ()
 
virtual int64 getMemoryUsage (bool inclusive) const =0
 NOTE: This level doesn't own any data apart from itself. More...
 

Static Public Member Functions

static UT_ThreadallocThread (SpinMode spin_mode, bool uses_tbb=true)
 
static int getNumProcessors ()
 
static int activeThreadCount ()
 This is only valid in debug builds. More...
 
static void resetNumProcessors ()
 
static ut_thread_id_t getMyThreadId ()
 
static ut_thread_id_t getMainThreadId ()
 
static int getMainSequentialThreadId ()
 
static int isMainThread ()
 
static bool isUTThreadCurrent ()
 
static bool isThreadingEnabled ()
 
static bool setThreadingEnabled (bool will_be_enabled)
 
static void pause (uint cycles)
 
static void yield (bool higher_only=false)
 
static int getMySequentialThreadIndex ()
 
static void configureMaxThreads (int maxthreads=0)
 
static void configureThreadStackSize (int stacksize)
 
static bool isMaxThreadsConfigured ()
 Returns true if configureMaxThreads() has been called at least once. More...
 
static bool minimizeThisThreadPriority ()
 

Protected Member Functions

virtual int waitThread (int block=1)=0
 
virtual int isValid ()
 
void killIdle ()
 
virtual void setState (State state)=0
 
 UT_Thread (SpinMode spin_mode, bool uses_tbb)
 

Static Protected Member Functions

static voidthreadWrapper (void *data)
 

Protected Attributes

volatile State myState
 
SpinMode mySpinMode
 
UTthreadFunc myCallback
 
voidmyCBData
 
const UT_TaskScopemyTaskScope
 
bool myUsesTBB
 

Friends

class UT_SubSystem
 

Detailed Description

Definition at line 58 of file UT_Thread.h.

Member Enumeration Documentation

Enumerator
ThreadSingleRun 
ThreadLowUsage 

Definition at line 82 of file UT_Thread.h.

Enumerator
ThreadIdle 
ThreadRunning 

Definition at line 71 of file UT_Thread.h.

Constructor & Destructor Documentation

virtual UT_Thread::~UT_Thread ( )
virtual
UT_Thread::UT_Thread ( const UT_Thread )
delete
UT_Thread::UT_Thread ( SpinMode  spin_mode,
bool  uses_tbb 
)
protected

Member Function Documentation

static int UT_Thread::activeThreadCount ( )
static

This is only valid in debug builds.

static UT_Thread* UT_Thread::allocThread ( SpinMode  spin_mode,
bool  uses_tbb = true 
)
static

Allocate a new thread

Parameters
spin_modeUse ThreadSingleRun to have it exit when the thread callback is finished. Otherwise, ThreadLowUsage will cause the thread to loop back and wait for more startThread() calls to run different thread callbacks in the same thread.
uses_tbbLeave at true unless you absolutely know that no TBB tasks will be spawned in thread callbacks.
static void UT_Thread::configureMaxThreads ( int  maxthreads = 0)
static

Configure the global number of tasks used by the system

  • The default value of 0 uses the number of logical cores on the system
  • A negative value wraps it from the number of logical cores. eg. -1 will use all cores except for 1.
  • If the negative value exceeds the number of logical cores, it is clamped to a value of 1.
    Note
    Only call this in the main thread when there are no tasks active.
    This function is NOT thread-safe.
static void UT_Thread::configureThreadStackSize ( int  stacksize)
static

Configure the default stack size for threads

  • A value of 0 uses the stack size of the main thread
  • A value larger than 0 will use that specific stack size
    Note
    Only call this in the main thread when there are no tasks active.
    This function is NOT thread-safe.
static int UT_Thread::getMainSequentialThreadId ( )
static
static ut_thread_id_t UT_Thread::getMainThreadId ( )
static
virtual int64 UT_Thread::getMemoryUsage ( bool  inclusive) const
pure virtual

NOTE: This level doesn't own any data apart from itself.

Implemented in UT_NullThread.

static int UT_Thread::getMySequentialThreadIndex ( )
inlinestatic

This function has been deprecated. Use SYS_SequentialThreadIndex::get() or SYSgetSTID instead.

Definition at line 193 of file UT_Thread.h.

static ut_thread_id_t UT_Thread::getMyThreadId ( )
static
Examples:
VEX/VEX_Ops.C.
static int UT_Thread::getNumProcessors ( )
static
virtual SpinMode UT_Thread::getSpinMode ( )
virtual
virtual State UT_Thread::getState ( )
virtual
int UT_Thread::isActive ( )
inline

Definition at line 285 of file UT_Thread.h.

static int UT_Thread::isMainThread ( )
inlinestatic

Definition at line 118 of file UT_Thread.h.

static bool UT_Thread::isMaxThreadsConfigured ( )
static

Returns true if configureMaxThreads() has been called at least once.

virtual int UT_Thread::isResourceHog ( ) const
virtual
static bool UT_Thread::isThreadingEnabled ( )
static

Returns true iff the current thread is allowed to create more tasks. This is sometimes disabled, to avoid needing to create a UT_TaskArena for small cases that won't get much benefit from threading. This should be checked by anything using tbb::parallel_for, tbb::parallel_invoke, or anything else creating TBB tasks.

static bool UT_Thread::isUTThreadCurrent ( )
static

Returns true if the current thread is a UT_Thread. Returns false if the current thread is either the main thread or a TBB thread.

virtual int UT_Thread::isValid ( )
protectedvirtual
void UT_Thread::killIdle ( )
protected
virtual void UT_Thread::killThread ( )
pure virtual

Implemented in UT_NullThread.

static bool UT_Thread::minimizeThisThreadPriority ( )
static

Sets the current thread to minimum priority according to the rules of the platform. This function fails if called on a thread that is not a running UT_Thread. Returns true if the operation was successful, otherwise returns false.

UT_Thread& UT_Thread::operator= ( const UT_Thread )
delete
static void UT_Thread::pause ( uint  cycles)
inlinestatic

Definition at line 157 of file UT_Thread.h.

static void UT_Thread::resetNumProcessors ( )
static

Reset the number of threads that is used by Houdini. This will reread the HOUDINI_MAXTHREADS setting.

Note
There should be no active tasks when this is called.
Only call this from the MAIN THREAD!
virtual int UT_Thread::restartThread ( )
pure virtual

Implemented in UT_NullThread.

virtual void UT_Thread::setSpinMode ( SpinMode  spin_mode)
virtual
virtual void UT_Thread::setState ( State  state)
protectedpure virtual

Implemented in UT_NullThread.

static bool UT_Thread::setThreadingEnabled ( bool  will_be_enabled)
static

This is used to disable (false) threading for the current thread, to avoid needing to create a UT_TaskArena for small cases that won't get much benefit from threading. It returns if it was enabled before. It is also used to re-enable (true) threading for the current thread.

virtual bool UT_Thread::startThread ( UTthreadFunc  func,
void data,
int  stacksize 
)
pure virtual

Implemented in UT_NullThread.

bool UT_Thread::startThread ( UTthreadFunc  func,
void data 
)
virtual int UT_Thread::suspendThread ( )
pure virtual

Implemented in UT_NullThread.

virtual void UT_Thread::threadEnded ( )
virtual
virtual void UT_Thread::threadStarted ( )
virtual
static void* UT_Thread::threadWrapper ( void data)
staticprotected
virtual void UT_Thread::waitForState ( State  desired)
pure virtual

Implemented in UT_NullThread.

virtual int UT_Thread::waitThread ( int  block = 1)
protectedpure virtual

Implemented in UT_NullThread.

static void UT_Thread::yield ( bool  higher_only = false)
static

Friends And Related Function Documentation

friend class UT_SubSystem
friend

Definition at line 325 of file UT_Thread.h.

Member Data Documentation

UTthreadFunc UT_Thread::myCallback
protected

Definition at line 311 of file UT_Thread.h.

void* UT_Thread::myCBData
protected

Definition at line 312 of file UT_Thread.h.

SpinMode UT_Thread::mySpinMode
protected

Definition at line 310 of file UT_Thread.h.

volatile State UT_Thread::myState
protected

Definition at line 309 of file UT_Thread.h.

const UT_TaskScope* UT_Thread::myTaskScope
protected

Definition at line 314 of file UT_Thread.h.

bool UT_Thread::myUsesTBB
protected

Definition at line 315 of file UT_Thread.h.


The documentation for this class was generated from the following file: