docs/html/Thread_8h_source.html
| | Jetson Inference
DNN Vision Library |
Thread.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 #ifndef __MULTITHREAD_H_
24 #define __MULTITHREAD_H_
25
26 #include <pthread.h>
27
28
35 typedef void* (*ThreadEntryFunction)( void* user_param );
36
37
45 {
46 public:
50Thread();
51
55virtual ~Thread();
56
60virtual void Run();
61
66bool Start();
67
72bool Start( ThreadEntryFunction entry, void* user_param=NULL );
73
78void Stop( bool wait=false );
79
83static void InitRealtime();
84
88static int GetMaxPriority();
89
93static int GetMinPriority();
94
99static int GetPriority( pthread_t* thread=NULL );
100
105static int SetPriority( int priority, pthread_t* thread=NULL );
106
110int GetPriorityLevel();
111
115bool SetPriorityLevel( int priority );
116
121static void Yield( unsigned int ms );
122
126inline pthread_t* GetThreadID() { return &mThreadID; }
127
131bool LockAffinity( unsigned int cpu );
132
138static bool SetAffinity( unsigned int cpu, pthread_t* thread=NULL );
139
143static int GetCPU();
144
145 protected:
146
147static void* DefaultEntry( void* param );
148
150bool mThreadStarted;
151 };
152
153 #endif
int GetPriorityLevel()
Get this thread's priority level.
static int GetCPU()
Look up which CPU core the thread is running on.
static void Yield(unsigned int ms)
Whatever thread you are calling from, yield the processor for the specified number of milliseconds.
bool SetPriorityLevel(int priority)
Set this thread's priority level.
bool LockAffinity(unsigned int cpu)
Lock this thread to a CPU core.
bool Start()
Start the thread.
static int GetMinPriority()
Get the minimum priority level avaiable.
pthread_t * GetThreadID()
Get thread identififer.
Definition: Thread.h:126
static int GetPriority(pthread_t *thread=NULL)
Get the priority level of the thread.
static bool SetAffinity(unsigned int cpu, pthread_t *thread=NULL)
Lock the specified thread's affinity to a CPU core.
static void * DefaultEntry(void *param)
pthread_t mThreadID
Definition: Thread.h:149
virtual ~Thread()
Destructor.
bool mThreadStarted
Definition: Thread.h:150
void Stop(bool wait=false)
Signal for the thread to stop running.
static void InitRealtime()
Prime the system for realtime use.
static int GetMaxPriority()
Get the maximum priority level available.
Thread()
Default constructor.
Thread class for launching an asynchronous operating-system dependent thread.
Definition: Thread.h:44
static int SetPriority(int priority, pthread_t *thread=NULL)
Set the priority level of the thread.
virtual void Run()
User-implemented thread main() function.
void *(* ThreadEntryFunction)(void *user_param)
Function pointer typedef representing a thread's main entry point.
Definition: Thread.h:35