Jetson Inference
DNN Vision Library

Thread class for launching an asynchronous operating-system dependent thread. More...

#include <Thread.h>

Public Member Functions

 Thread ()
 Default constructor. More...
 
virtual ~Thread ()
 Destructor. More...
 
virtual void Run ()
 User-implemented thread main() function. More...
 
bool Start ()
 Start the thread. More...
 
bool Start (ThreadEntryFunction entry, void *user_param=NULL)
 Start the thread, utilizing an entry function pointer provided by the user. More...
 
void Stop (bool wait=false)
 Signal for the thread to stop running. More...
 
int GetPriorityLevel ()
 Get this thread's priority level. More...
 
bool SetPriorityLevel (int priority)
 Set this thread's priority level. More...
 
pthread_t * GetThreadID ()
 Get thread identififer. More...
 
bool LockAffinity (unsigned int cpu)
 Lock this thread to a CPU core. More...
 

Static Public Member Functions

static void InitRealtime ()
 Prime the system for realtime use. More...
 
static int GetMaxPriority ()
 Get the maximum priority level available. More...
 
static int GetMinPriority ()
 Get the minimum priority level avaiable. More...
 
static int GetPriority (pthread_t *thread=NULL)
 Get the priority level of the thread. More...
 
static int SetPriority (int priority, pthread_t *thread=NULL)
 Set the priority level of the thread. More...
 
static void Yield (unsigned int ms)
 Whatever thread you are calling from, yield the processor for the specified number of milliseconds. More...
 
static bool SetAffinity (unsigned int cpu, pthread_t *thread=NULL)
 Lock the specified thread's affinity to a CPU core. More...
 
static int GetCPU ()
 Look up which CPU core the thread is running on. More...
 

Static Protected Member Functions

static void * DefaultEntry (void *param)
 

Protected Attributes

pthread_t mThreadID
 
bool mThreadStarted
 

Detailed Description

Thread class for launching an asynchronous operating-system dependent thread.

To make your own thread, provide a function pointer of the thread's entry point, or inherit from this class and implement your own Run() function.

Constructor & Destructor Documentation

◆ Thread()

Thread::Thread ( )

Default constructor.

◆ ~Thread()

virtual Thread::~Thread ( )
virtual

Destructor.

Automatically stops the thread.

Member Function Documentation

◆ DefaultEntry()

static void* Thread::DefaultEntry ( void *  param)
staticprotected

◆ GetCPU()

static int Thread::GetCPU ( )
static

Look up which CPU core the thread is running on.

◆ GetMaxPriority()

static int Thread::GetMaxPriority ( )
static

Get the maximum priority level available.

◆ GetMinPriority()

static int Thread::GetMinPriority ( )
static

Get the minimum priority level avaiable.

◆ GetPriority()

static int Thread::GetPriority ( pthread_t *  thread = NULL)
static

Get the priority level of the thread.

Parameters
threadThe thread, or if NULL, the currently running thread.

◆ GetPriorityLevel()

int Thread::GetPriorityLevel ( )

Get this thread's priority level.

◆ GetThreadID()

pthread_t* Thread::GetThreadID ( )
inline

Get thread identififer.

◆ InitRealtime()

static void Thread::InitRealtime ( )
static

Prime the system for realtime use.

Mostly this is locking a large group of pages into memory.

◆ LockAffinity()

bool Thread::LockAffinity ( unsigned int  cpu)

Lock this thread to a CPU core.

◆ Run()

virtual void Thread::Run ( )
virtual

User-implemented thread main() function.

◆ SetAffinity()

static bool Thread::SetAffinity ( unsigned int  cpu,
pthread_t *  thread = NULL 
)
static

Lock the specified thread's affinity to a CPU core.

Parameters
cpuThe CPU core to lock the thread to.
threadThe thread, or if NULL, the currently running thread.

◆ SetPriority()

static int Thread::SetPriority ( int  priority,
pthread_t *  thread = NULL 
)
static

Set the priority level of the thread.

Parameters
threadThe thread, or if NULL, the currently running thread.

◆ SetPriorityLevel()

bool Thread::SetPriorityLevel ( int  priority)

Set this thread's priority level.

◆ Start() [1/2]

bool Thread::Start ( )

Start the thread.

This will asynchronously call the Run() function.

Returns
False if an error occurred and the thread could not be started.

◆ Start() [2/2]

bool Thread::Start ( ThreadEntryFunction  entry,
void *  user_param = NULL 
)

Start the thread, utilizing an entry function pointer provided by the user.

Returns
False if an error occurred and the thread could not be started.

◆ Stop()

void Thread::Stop ( bool  wait = false)

Signal for the thread to stop running.

If wait is true, Stop() will block until the thread has exited.

◆ Yield()

static void Thread::Yield ( unsigned int  ms)
static

Whatever thread you are calling from, yield the processor for the specified number of milliseconds.

Accuracy may vary wildly the lower you go, and depending on the platform.

Member Data Documentation

◆ mThreadID

pthread_t Thread::mThreadID
protected

◆ mThreadStarted

bool Thread::mThreadStarted
protected

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