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:
00100 UThread(Priority priority = kPNormal);
00101
00108 virtual ~UThread();
00109
00115 void start();
00116
00123 void kill();
00124
00131 void join(bool killFirst = false);
00132
00137 void setPriority(Priority priority);
00138
00145 void setAffinity(int cpu = 0);
00146
00150 bool isCreating() const;
00151
00155 bool isRunning() const;
00156
00160 bool isIdle() const;
00161
00165 bool isKilled() const;
00166
00167 Handle getThreadHandle() const {return handle_;}
00168
00169
00170 protected:
00171
00172 private:
00179 virtual void mainLoopBegin() {}
00180
00190 virtual void mainLoop() = 0;
00191
00199 virtual void mainLoopKill() {}
00200
00207 virtual void mainLoopEnd() {}
00208
00209
00210
00211
00212
00213 void ThreadMain();
00214
00215
00216
00217
00218
00219 void applyPriority();
00220
00221
00222
00223
00224
00225 void applyAffinity();
00226
00227
00228
00229
00230
00231
00232
00233 int Create(
00234 Handle * const & H = 0,
00235 const bool & CreateDetached = false,
00236 const unsigned int & StackSize = 0,
00237 const bool & CancelEnable = false,
00238 const bool & CancelAsync = false
00239 ) const;
00240
00241
00242 static int Join( Handle H )
00243 { return UThreadC<void>::Join(H); }
00244 static int Kill( Handle H )
00245 { return UThreadC<void>::Kill(H); }
00246 static int Detach( Handle H )
00247 { return UThreadC<void>::Detach(H); }
00248
00249 private:
00250 void operator=(UThread & t) {}
00251 UThread( const UThread & t ) {}
00252
00253 private:
00254 enum State{kSIdle, kSCreating, kSRunning, kSKilled};
00255 State state_;
00256 Priority priority_;
00257 Handle handle_;
00258 #ifdef _WIN32
00259 int threadId_;
00260 #else
00261 unsigned long threadId_;
00262 #endif
00263 int cpuAffinity_;
00264 UMutex killSafelyMutex_;
00265 UMutex runningMutex_;
00266 };
00267
00268 #endif // UTHREADNODE_H