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 
44 class Thread
45 {
46 public:
50  Thread();
51 
55  virtual ~Thread();
56 
60  virtual void Run();
61 
66  bool StartThread();
67 
72  bool StartThread( ThreadEntryFunction entry, void* user_param=NULL );
73 
77  void StopThread();
78 
82  static void InitRealtime();
83 
87  static int GetMaxPriority();
88 
92  static int GetMinPriority();
93 
98  static int GetPriority( pthread_t* thread=NULL );
99 
104  static int SetPriority( int priority, pthread_t* thread=NULL );
105 
109  int GetPriorityLevel();
110 
114  bool SetPriorityLevel( int priority );
115 
121  static void Yield( unsigned int ms );
122 
126  inline pthread_t* GetThreadID() { return &mThreadID; }
127 
131  bool LockAffinity( unsigned int cpu );
132 
138  static bool SetAffinity( unsigned int cpu, pthread_t* thread=NULL );
139 
143  static int GetCPU();
144 
145 protected:
146 
147 
148 
149  static void* DefaultEntry( void* param );
150 
151  pthread_t mThreadID;
153 };
154 
155 #endif
static void * DefaultEntry(void *param)
void *(* ThreadEntryFunction)(void *user_param)
Function pointer typedef representing a thread&#39;s main entry point.
Definition: Thread.h:35
static void Yield(unsigned int ms)
Whatever thread you are calling from, yield the processor for the specified number of milliseconds...
bool mThreadStarted
Definition: Thread.h:152
pthread_t * GetThreadID()
Get thread identififer.
Definition: Thread.h:126
static void InitRealtime()
Prime the system for realtime use.
static bool SetAffinity(unsigned int cpu, pthread_t *thread=NULL)
Lock the specified thread&#39;s affinity to a CPU core.
virtual ~Thread()
Destructor.
static int SetPriority(int priority, pthread_t *thread=NULL)
Set the priority level of the thread.
void StopThread()
Halt execution of the thread.
static int GetMaxPriority()
Get the maximum priority level available.
pthread_t mThreadID
Definition: Thread.h:151
bool SetPriorityLevel(int priority)
Set this thread&#39;s priority level.
static int GetMinPriority()
Get the minimum priority level avaiable.
static int GetPriority(pthread_t *thread=NULL)
Get the priority level of the thread.
int GetPriorityLevel()
Get this thread&#39;s priority level.
Thread class for launching an asynchronous operating-system dependent thread.
Definition: Thread.h:44
virtual void Run()
User-implemented thread main() function.
bool StartThread()
Start the thread.
bool LockAffinity(unsigned int cpu)
Lock this thread to a CPU core.
Thread()
Default constructor.
static int GetCPU()
Look up which CPU core the thread is running on.