Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef UTHREADNODE_H
00021 #define UTHREADNODE_H
00022
00023 #include "rtabmap/utilite/UtiLiteExp.h"
00024
00025 #include "rtabmap/utilite/UThreadC.h"
00026
00086 class UTILITE_EXP UThread : public UThreadC<void>
00087 {
00088 public:
00092 enum Priority{kPLow, kPBelowNormal, kPNormal, kPAboveNormal, kPRealTime};
00093
00094 public:
00095
00096 static unsigned long currentThreadId() {return (unsigned long)UThreadC<void>::Self();}
00097
00098 public:
00104 UThread(Priority priority = kPNormal);
00105
00112 virtual ~UThread();
00113
00119 void start();
00120
00127 void kill();
00128
00135 void join(bool killFirst = false);
00136
00141 void setPriority(Priority priority);
00142
00149 void setAffinity(int cpu = 0);
00150
00154 bool isCreating() const;
00155
00159 bool isRunning() const;
00160
00164 bool isIdle() const;
00165
00169 bool isKilled() const;
00170
00171 Handle getThreadHandle() const {return handle_;}
00172 unsigned long getThreadId() const {return threadId_;}
00173
00174 protected:
00175
00176 private:
00183 virtual void mainLoopBegin() {}
00184
00194 virtual void mainLoop() = 0;
00195
00203 virtual void mainLoopKill() {}
00204
00211 virtual void mainLoopEnd() {}
00212
00213
00214
00215
00216
00217 void ThreadMain();
00218
00219
00220
00221
00222
00223 void applyPriority();
00224
00225
00226
00227
00228
00229 void applyAffinity();
00230
00231
00232
00233
00234
00235
00236
00237 int Create(
00238 Handle * const & H = 0,
00239 const bool & CreateDetached = false,
00240 const unsigned int & StackSize = 0,
00241 const bool & CancelEnable = false,
00242 const bool & CancelAsync = false
00243 ) const;
00244
00245
00246 static int Join( Handle H )
00247 { return UThreadC<void>::Join(H); }
00248 #ifndef ANDROID
00249 static int Kill( Handle H )
00250 { return UThreadC<void>::Kill(H); }
00251 #endif
00252 static int Detach( Handle H )
00253 { return UThreadC<void>::Detach(H); }
00254
00255 private:
00256 void operator=(UThread & t) {}
00257 UThread( const UThread & t ) : state_(kSIdle) {}
00258
00259 private:
00260 enum State{kSIdle, kSCreating, kSRunning, kSKilled};
00261 State state_;
00262 Priority priority_;
00263 Handle handle_;
00264 unsigned long threadId_;
00265 int cpuAffinity_;
00266 UMutex killSafelyMutex_;
00267 UMutex runningMutex_;
00268 };
00269
00270 #endif // UTHREADNODE_H