docs/html/group__threads.html
| | Jetson Inference
DNN Vision Library |
Multithreading Utilities Library (jetson-utils)
Mutex, events, threads, and process objects based on pthreads. More...
|
|
| 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...
|
| |
|
|
| 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.
|
|
| | 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...
|
| |
|
| | pthread_cond_t | mID | | | | Mutex | mQueryMutex | | | | bool | mQuery | | | | bool | mAutoReset | | |
|
| Event::Event | ( | bool | auto_reset = true | ) | |
| inline |
Event constructor.
By default, it will automatically be reset when it's raised.
Parameters
| auto_reset | Once this event has been raised, should it automatically be reset? |
|
| Event::~Event | ( | | ) | |
| inline |
Destructor.
|
| pthread_cond_t* Event::GetID | ( | | ) | |
| inline |
Get the Event object.
|
| bool Event::Query | ( | | ) | |
| inline |
Query the status of this event.
ReturnsTrue if the event is raised, false if not.
|
| void Event::Reset | ( | | ) | |
| inline |
Reset the event status to un-raised.
|
| bool Event::Wait | ( | | ) | |
| inline |
Wait until this event is raised.
It is likely this will block this thread (and will never timeout).
See alsoWake
|
| bool Event::Wait | ( | const timespec & | timeout | ) | |
| inline |
Wait for a specified amount of time until this event is raised or timeout occurs.
See alsoWake
|
| bool Event::Wait | ( | uint64_t | timeout | ) | |
| inline |
Wait for a specified number of milliseconds until this event is raised or timeout occurs.
See alsoWake
|
| bool Event::WaitNs | ( | uint64_t | timeout | ) | |
| inline |
Wait for a specified number of nanoseconds until this event is raised or timeout occurs.
See alsoWake
|
| bool Event::WaitUs | ( | uint64_t | timeout | ) | |
| inline |
Wait for a specified number of microseconds until this event is raised or timeout occurs.
See alsoWake
|
| void Event::Wake | ( | | ) | |
| inline |
Raise the event.
Any threads waiting on this event will be woken up.
|
| bool Event::mAutoReset |
| protected |
|
| pthread_cond_t Event::mID |
| protected |
|
| bool Event::mQuery |
| protected |
|
| Mutex Event::mQueryMutex |
| 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.
|
|
| | 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...
|
| |
|
| | pthread_mutex_t | mID | | |
|
| Mutex::Mutex | ( | | ) | |
| inline |
Constructor.
|
| Mutex::~Mutex | ( | | ) | |
| inline |
Destructor.
|
| bool Mutex::AttemptLock | ( | | ) | |
| inline |
If the lock is free, aquire it.
Otherwise, return without waiting for it to become available.
ReturnsTrue if the lock was aquired, false if not.
|
| pthread_mutex_t* Mutex::GetID | ( | | ) | |
| inline |
Get the mutex object.
|
| void Mutex::Lock | ( | | ) | |
| 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.
|
| void Mutex::Sync | ( | | ) | |
| inline |
Wait for the lock, then release it immediately.
Use this in situations where you are waiting for an event to occur.
|
| void Mutex::Unlock | ( | | ) | |
| inline |
Release the lock.
|
| pthread_mutex_t Mutex::mID |
| protected |
| class Process |
Static functions for retrieving information about the running process.
|
|
| 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 void Process::Fork | ( | | ) | |
| static |
Duplicate the calling process.
|
| static std::string Process::GetCommandLine | ( | pid_t | pid = -1 | ) | |
| 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 std::string Process::GetExecutableDir | ( | pid_t | pid = -1 | ) | |
| 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 std::string Process::GetExecutablePath | ( | pid_t | pid = -1 | ) | |
| 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 pid_t Process::GetID | ( | | ) | |
| static |
Get this process ID (PID)
|
| static pid_t Process::GetParentID | ( | | ) | |
| static |
Get the parent's process ID.
|
| static std::string Process::GetWorkingDir | ( | pid_t | pid = -1 | ) | |
| 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.
|
|
| 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...
|
| |
|
|
| | 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...
|
| |
|
| | 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.
| Enumerator |
|---|
| Read |
Read the next buffer.
| | ReadOnce |
Read the next buffer, but only if it hasn't been read before.
| | ReadLatest |
Read the latest buffer in the queue, skipping other buffers that may not have been read.
| | ReadLatestOnce |
Combination of ReadOnce and ReadLatest flags.
| | Write |
Write the next buffer.
| | Threaded |
Buffers should be thread-safe (enabled by default).
| | ZeroCopy |
Buffers should be allocated in mapped CPU/GPU zeroCopy memory (otherwise GPU only)
|
|
| RingBuffer::RingBuffer | ( | uint32_t | flags = Threaded | ) | |
| inline |
Construct a new ring buffer.
|
| RingBuffer::~RingBuffer | ( | | ) | |
| inline |
Destructor.
|
| bool RingBuffer::Alloc | ( | uint32_t | numBuffers, |
| | | size_t | size, |
| | | uint32_t | flags = 0 |
| | ) | | |
| 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.
Returnstrue if the allocations succeeded or was previously done. false if a memory allocation error occurred.
|
| void RingBuffer::Free | ( | | ) | |
| inline |
Free the buffer allocations.
|
| uint32_t RingBuffer::GetFlags | ( | | ) | const |
| inline |
Get the flags of the ring buffer.
|
| void* RingBuffer::Next | ( | uint32_t | flags | ) | |
| inline |
Get the next read/write buffer and advance the position in the queue.
|
| void* RingBuffer::Peek | ( | uint32_t | flags | ) | |
| inline |
Get the next read/write buffer without advancing the position in the queue.
|
| void RingBuffer::SetFlags | ( | uint32_t | flags | ) | |
| inline |
Set the ring buffer's flags.
|
| void RingBuffer::SetThreaded | ( | bool | threaded | ) | |
| inline |
Enable or disable multi-threading.
|
| void** RingBuffer::mBuffers |
| protected |
|
| size_t RingBuffer::mBufferSize |
| protected |
|
| uint32_t RingBuffer::mFlags |
| protected |
|
| uint32_t RingBuffer::mLatestRead |
| protected |
|
| uint32_t RingBuffer::mLatestWrite |
| protected |
|
| Mutex RingBuffer::mMutex |
| protected |
|
| uint32_t RingBuffer::mNumBuffers |
| protected |
|
| bool RingBuffer::mReadOnce |
| 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.
|
|
| | 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 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 void * | DefaultEntry (void *param) | | | |
| | pthread_t | mThreadID | | | | bool | mThreadStarted | | |
| Thread::Thread | ( | | ) | |
Default constructor.
|
| virtual Thread::~Thread | ( | | ) | |
| virtual |
Destructor.
Automatically stops the thread.
|
| static void* Thread::DefaultEntry | ( | void * | param | ) | |
| staticprotected |
|
| static int Thread::GetCPU | ( | | ) | |
| static |
Look up which CPU core the thread is running on.
|
| static int Thread::GetMaxPriority | ( | | ) | |
| static |
Get the maximum priority level available.
|
| static int Thread::GetMinPriority | ( | | ) | |
| static |
Get the minimum priority level avaiable.
|
| static int Thread::GetPriority | ( | pthread_t * | thread = NULL | ) | |
| static |
Get the priority level of the thread.
Parameters
| thread | The thread, or if NULL, the currently running thread. |
| int Thread::GetPriorityLevel | ( | | ) | |
Get this thread's priority level.
|
| pthread_t* Thread::GetThreadID | ( | | ) | |
| inline |
Get thread identififer.
|
| static void Thread::InitRealtime | ( | | ) | |
| 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 void Thread::Run | ( | | ) | |
| virtual |
User-implemented thread main() function.
|
| static bool Thread::SetAffinity | ( | unsigned int | cpu, |
| | | pthread_t * | thread = NULL |
| | ) | | |
| static |
Lock the specified thread's affinity to a CPU core.
Parameters
| cpu | The CPU core to lock the thread to. | | thread | The thread, or if NULL, the currently running thread. |
|
| static int Thread::SetPriority | ( | int | priority, |
| | | pthread_t * | thread = NULL |
| | ) | | |
| static |
Set the priority level of the thread.
Parameters
| 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.
ReturnsFalse if an error occurred and the thread could not be started.
| bool Thread::Start | ( | ThreadEntryFunction | entry, |
| | | void * | user_param = NULL |
| | ) | | |
Start the thread, utilizing an entry function pointer provided by the user.
ReturnsFalse if an error occurred and the thread could not be started.
| 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 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.
|
| pthread_t Thread::mThreadID |
| protected |
|
| bool Thread::mThreadStarted |
| 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.