UThread.h
Go to the documentation of this file.
1 /*
2 * utilite is a cross-platform library with
3 * useful utilities for fast and small developing.
4 * Copyright (C) 2010 Mathieu Labbe
5 *
6 * utilite is free library: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * utilite is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef UTHREADNODE_H
21 #define UTHREADNODE_H
22 
23 #include "rtabmap/utilite/utilite_export.h" // DLL export/import defines
24 
26 
86 class UTILITE_EXPORT UThread : public UThreadC<void>
87 {
88 public:
92  enum Priority{kPLow, kPBelowNormal, kPNormal, kPAboveNormal, kPRealTime};
93 
94 public:
95  //return caller thread id
96  static unsigned long currentThreadId() {return (unsigned long)UThreadC<void>::Self();}
97 
98 public:
104  UThread(Priority priority = kPNormal);
105 
112  virtual ~UThread();
113 
119  void start();
120 
127  void kill();
128 
135  void join(bool killFirst = false);
136 
141  void setPriority(Priority priority);
142 
149  void setAffinity(int cpu = 0);
150 
154  bool isCreating() const;
155 
159  bool isRunning() const;
160 
164  bool isIdle() const;
165 
169  bool isKilled() const;
170 
171  Handle getThreadHandle() const {return handle_;}
172  unsigned long getThreadId() const {return threadId_;}
173 
174 protected:
175 
176 private:
183  virtual void mainLoopBegin() {}
184 
194  virtual void mainLoop() = 0;
195 
203  virtual void mainLoopKill() {}
204 
211  virtual void mainLoopEnd() {}
212 
213  /*
214  * Inherited method ThreadMain() from Thread.
215  * @see Thread<void>
216  */
217  void ThreadMain();
218 
219  /*
220  * Apply thread priority. This is called when starting the thread.
221  * *@todo : Support pthread
222  */
223  void applyPriority();
224 
225  /*
226  * Apply cpu affinity. This is called when starting the thread.
227  * *@todo : Support Windows
228  */
229  void applyAffinity();
230 
231  /*
232  * Inherited method Create() from Thread.
233  * Here we force this function to be private so the
234  * inherited class can't have access to it.
235  * @see Thread<void>
236  */
237  int Create(
238  Handle * const & H = 0,
239  const bool & CreateDetached = false,
240  const unsigned int & StackSize = 0,
241  const bool & CancelEnable = false, // UNUSED
242  const bool & CancelAsync = false // UNUSED
243  ) const;
244 
245  //Methods from UThread<void> class hided
246  static int Join( Handle H )
247  { return UThreadC<void>::Join(H); }
248 #ifndef ANDROID
249  static int Kill( Handle H )
250  { return UThreadC<void>::Kill(H); }
251 #endif
252  static int Detach( Handle H )
253  { return UThreadC<void>::Detach(H); }
254 
255 private:
256  void operator=(UThread &) {}
257  UThread( const UThread &) : state_(kSIdle) {}
258 
259 private:
260  enum State{kSIdle, kSCreating, kSRunning, kSKilled}; /* Enum of states. */
261  State state_; /* The thread state. */
262  Priority priority_; /* The thread priority. */
263  Handle handle_; /* The thread handle. */
264  unsigned long threadId_; /* The thread id. */
265  int cpuAffinity_; /* The cpu affinity. */
266  UMutex killSafelyMutex_; /* Mutex used to protect the kill() method. */
267  UMutex runningMutex_; /* Mutex used to notify the join method when the thread has finished. */
268 };
269 
270 #endif // UTHREADNODE_H
H
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[ *:*] noreverse nowriteback set trange[ *:*] noreverse nowriteback set urange[ *:*] noreverse nowriteback set vrange[ *:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
UThread::currentThreadId
static unsigned long currentThreadId()
Definition: UThread.h:96
UThread::Join
static int Join(Handle H)
Definition: UThread.h:246
UThread::priority_
Priority priority_
Definition: UThread.h:262
UThread::UThread
UThread(const UThread &)
Definition: UThread.h:257
UThread::state_
State state_
Definition: UThread.h:261
UThreadC::Create
static int Create(const Handler &Function, Thread_C_R Param, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false)
Definition: Posix/UThreadC.h:97
UThreadC::Kill
static int Kill(Handle H)
Definition: Posix/UThreadC.h:168
UThread::Kill
static int Kill(Handle H)
Definition: UThread.h:249
UThread::Priority
Priority
Definition: UThread.h:92
UThread::getThreadId
unsigned long getThreadId() const
Definition: UThread.h:172
UThread::operator=
void operator=(UThread &)
Definition: UThread.h:256
UMutex
Definition: UMutex.h:54
UThreadC::ThreadMain
virtual void ThreadMain(Thread_R)=0
UThread::mainLoopEnd
virtual void mainLoopEnd()
Definition: UThread.h:211
UThread::Detach
static int Detach(Handle H)
Definition: UThread.h:252
UThreadC
Definition: Posix/UThreadC.h:66
State
UThreadC::Detach
static int Detach(Handle H)
Definition: Posix/UThreadC.h:172
UThread::mainLoopKill
virtual void mainLoopKill()
Definition: UThread.h:203
UThread::runningMutex_
UMutex runningMutex_
Definition: UThread.h:267
UThread
Definition: UThread.h:86
UThreadC::Self
static Handle Self()
Definition: Posix/UThreadC.h:92
UThread::cpuAffinity_
int cpuAffinity_
Definition: UThread.h:265
UThread::handle_
Handle handle_
Definition: UThread.h:263
applyAffinity
static void applyAffinity(Mem *pRec, char affinity, u8 enc)
Definition: sqlite3.c:66302
UThread::mainLoopBegin
virtual void mainLoopBegin()
Definition: UThread.h:183
UThreadC.h
UThread::killSafelyMutex_
UMutex killSafelyMutex_
Definition: UThread.h:266
UThread::getThreadHandle
Handle getThreadHandle() const
Definition: UThread.h:171
UThreadC::Join
static int Join(Handle H)
Definition: Posix/UThreadC.h:164
UThread::threadId_
unsigned long threadId_
Definition: UThread.h:264


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:23