Jetson Inference
DNN Vision Library
|
Mutex, events, threads, and process objects based on pthreads. More...
Classes | |
class | Event |
Event object for signalling other threads. More... | |
class | Mutex |
A lightweight mutual exclusion lock. More... | |
class | Process |
Static functions for retrieving information about the running process. More... | |
class | RingBuffer |
Thread-safe circular ring buffer queue. More... | |
class | Thread |
Thread class for launching an asynchronous operating-system dependent thread. More... | |
Typedefs | |
typedef void *(* | ThreadEntryFunction) (void *user_param) |
Function pointer typedef representing a thread's main entry point. More... | |
Mutex, events, threads, and process objects based on pthreads.
class Event |
Event object for signalling other threads.
Public Member Functions | |
Event (bool auto_reset=true) | |
Event constructor. More... | |
~Event () | |
Destructor. More... | |
void | Wake () |
Raise the event. More... | |
void | Reset () |
Reset the event status to un-raised. More... | |
bool | Query () |
Query the status of this event. More... | |
bool | Wait () |
Wait until this event is raised. More... | |
bool | Wait (const timespec &timeout) |
Wait for a specified amount of time until this event is raised or timeout occurs. More... | |
bool | Wait (uint64_t timeout) |
Wait for a specified number of milliseconds until this event is raised or timeout occurs. More... | |
bool | WaitNs (uint64_t timeout) |
Wait for a specified number of nanoseconds until this event is raised or timeout occurs. More... | |
bool | WaitUs (uint64_t timeout) |
Wait for a specified number of microseconds until this event is raised or timeout occurs. More... | |
pthread_cond_t * | GetID () |
Get the Event object. More... | |
Protected Attributes | |
pthread_cond_t | mID |
Mutex | mQueryMutex |
bool | mQuery |
bool | mAutoReset |
|
inline |
Event constructor.
By default, it will automatically be reset when it's raised.
auto_reset | Once this event has been raised, should it automatically be reset? |
|
inline |
Destructor.
|
inline |
Get the Event object.
|
inline |
Query the status of this event.
|
inline |
Reset the event status to un-raised.
|
inline |
Wait until this event is raised.
It is likely this will block this thread (and will never timeout).
|
inline |
Wait for a specified amount of time until this event is raised or timeout occurs.
|
inline |
Wait for a specified number of milliseconds until this event is raised or timeout occurs.
|
inline |
Wait for a specified number of nanoseconds until this event is raised or timeout occurs.
|
inline |
Wait for a specified number of microseconds until this event is raised or timeout occurs.
|
inline |
Raise the event.
Any threads waiting on this event will be woken up.
|
protected |
|
protected |
|
protected |
|
protected |
class Mutex |
A lightweight mutual exclusion lock.
It is very fast to check if the mutex is available, lock it, and release it. However, if the mutex is unavailable when you attempt to lock it, execution of the thread will stop until it becomes available.
Public Member Functions | |
Mutex () | |
Constructor. More... | |
~Mutex () | |
Destructor. More... | |
bool | AttemptLock () |
If the lock is free, aquire it. More... | |
void | Lock () |
Aquire the lock, whenever it becomes available. More... | |
void | Unlock () |
Release the lock. More... | |
void | Sync () |
Wait for the lock, then release it immediately. More... | |
pthread_mutex_t * | GetID () |
Get the mutex object. More... | |
Protected Attributes | |
pthread_mutex_t | mID |
|
inline |
Constructor.
|
inline |
Destructor.
|
inline |
If the lock is free, aquire it.
Otherwise, return without waiting for it to become available.
|
inline |
Get the mutex object.
|
inline |
Aquire the lock, whenever it becomes available.
This could mean just a few instructions if the lock is already free, or to block the thread if it isn't.
|
inline |
Wait for the lock, then release it immediately.
Use this in situations where you are waiting for an event to occur.
|
inline |
Release the lock.
|
protected |
class Process |
Static functions for retrieving information about the running process.
Static Public Member Functions | |
static pid_t | GetID () |
Get this process ID (PID) More... | |
static pid_t | GetParentID () |
Get the parent's process ID. More... | |
static std::string | GetCommandLine (pid_t pid=-1) |
Retrieve the command line of the process with the specified PID, or of this calling process if PID is -1 (which is the default). More... | |
static std::string | GetExecutablePath (pid_t pid=-1) |
Retrieve the absolute path of the process with the specified PID, or of this calling process if PID is -1 (which is the default). More... | |
static std::string | GetExecutableDir (pid_t pid=-1) |
Retrieve the directory that the process executable resides in. More... | |
static std::string | GetWorkingDir (pid_t pid=-1) |
Retrieve the current working directory of the process. More... | |
static void | Fork () |
Duplicate the calling process. More... | |
|
static |
Duplicate the calling process.
|
static |
Retrieve the command line of the process with the specified PID, or of this calling process if PID is -1 (which is the default).
|
static |
Retrieve the directory that the process executable resides in.
For example, if the process executable is located at /usr/bin/exe
, then GetExecutableDir()
would return the path /usr/bin
. If the specified PID is -1, then the calling process will be used.
|
static |
Retrieve the absolute path of the process with the specified PID, or of this calling process if PID is -1 (which is the default).
This path will include the process' filename.
|
static |
Get this process ID (PID)
|
static |
Get the parent's process ID.
|
static |
Retrieve the current working directory of the process.
If the specified PID is -1, then the calling process will be used.
class RingBuffer |
Thread-safe circular ring buffer queue.
Public Types | |
enum | Flags { Read = (1 << 0), ReadOnce = (1 << 1) | Read, ReadLatest = (1 << 2) | Read, ReadLatestOnce = (1 << 3) | ReadLatest, Write = (1 << 4), Threaded = (1 << 5), ZeroCopy = (1 << 6) } |
Ring buffer flags. More... | |
Public Member Functions | |
RingBuffer (uint32_t flags=Threaded) | |
Construct a new ring buffer. More... | |
~RingBuffer () | |
Destructor. More... | |
bool | Alloc (uint32_t numBuffers, size_t size, uint32_t flags=0) |
Allocate memory for a set of buffers, where each buffer has the specified size. More... | |
void | Free () |
Free the buffer allocations. More... | |
void * | Peek (uint32_t flags) |
Get the next read/write buffer without advancing the position in the queue. More... | |
void * | Next (uint32_t flags) |
Get the next read/write buffer and advance the position in the queue. More... | |
uint32_t | GetFlags () const |
Get the flags of the ring buffer. More... | |
void | SetFlags (uint32_t flags) |
Set the ring buffer's flags. More... | |
void | SetThreaded (bool threaded) |
Enable or disable multi-threading. More... | |
Protected Attributes | |
uint32_t | mNumBuffers |
uint32_t | mLatestRead |
uint32_t | mLatestWrite |
uint32_t | mFlags |
void ** | mBuffers |
size_t | mBufferSize |
bool | mReadOnce |
Mutex | mMutex |
enum RingBuffer::Flags |
Ring buffer flags.
|
inline |
Construct a new ring buffer.
|
inline |
Destructor.
|
inline |
Allocate memory for a set of buffers, where each buffer has the specified size.
If the requested allocation is compatible with what was already allocated, this will return true
without performing additional allocations. Otherwise, the previous buffers are released and new ones are allocated.
true
if the allocations succeeded or was previously done. false
if a memory allocation error occurred.
|
inline |
Free the buffer allocations.
|
inline |
Get the flags of the ring buffer.
|
inline |
Get the next read/write buffer and advance the position in the queue.
|
inline |
Get the next read/write buffer without advancing the position in the queue.
|
inline |
Set the ring buffer's flags.
|
inline |
Enable or disable multi-threading.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
class Thread |
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.
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 |
Thread::Thread | ( | ) |
Default constructor.
|
virtual |
Destructor.
Automatically stops the thread.
|
staticprotected |
|
static |
Look up which CPU core the thread is running on.
|
static |
Get the maximum priority level available.
|
static |
Get the minimum priority level avaiable.
|
static |
Get the priority level of the thread.
thread | The thread, or if NULL, the currently running thread. |
int Thread::GetPriorityLevel | ( | ) |
Get this thread's priority level.
|
inline |
Get thread identififer.
|
static |
Prime the system for realtime use.
Mostly this is locking a large group of pages into memory.
bool Thread::LockAffinity | ( | unsigned int | cpu | ) |
Lock this thread to a CPU core.
|
virtual |
User-implemented thread main() function.
|
static |
Lock the specified thread's affinity to a CPU core.
cpu | The CPU core to lock the thread to. |
thread | The thread, or if NULL, the currently running thread. |
|
static |
Set the priority level of the thread.
thread | The thread, or if NULL, the currently running thread. |
bool Thread::SetPriorityLevel | ( | int | priority | ) |
Set this thread's priority level.
bool Thread::Start | ( | ) |
Start the thread.
This will asynchronously call the Run() function.
bool Thread::Start | ( | ThreadEntryFunction | entry, |
void * | user_param = NULL |
||
) |
Start the thread, utilizing an entry function pointer provided by the user.
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.
|
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.
|
protected |
|
protected |
typedef void*(* ThreadEntryFunction) (void *user_param) |
Function pointer typedef representing a thread's main entry point.
A user-defined parameter is passed through such that the user can pass data or other value to their thread so that it can self-identify.