00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifndef Foundation_Thread_INCLUDED
00076 #define Foundation_Thread_INCLUDED
00077
00078
00079 #include "VMS/Foundation.h"
00080 #include "VMS/Mutex.h"
00081
00082 #include "VMS/Thread_POSIX.h"
00083
00084
00085 namespace Poco {
00086
00087
00088 class Runnable;
00089 class ThreadLocalStorage;
00090
00091
00092 class Foundation_API Thread: private ThreadImpl
00100 {
00101 public:
00102 enum Priority
00104 {
00105 PRIO_LOWEST = PRIO_LOWEST_IMPL,
00106 PRIO_LOW = PRIO_LOW_IMPL,
00107 PRIO_NORMAL = PRIO_NORMAL_IMPL,
00108 PRIO_HIGH = PRIO_HIGH_IMPL,
00109 PRIO_HIGHEST = PRIO_HIGHEST_IMPL
00110 };
00111
00112 Thread();
00114
00115 Thread(const std::string& name);
00117
00118 ~Thread();
00120
00121 int id() const;
00123
00124 std::string name() const;
00126
00127 std::string getName() const;
00129
00130 void setName(const std::string& name);
00132
00133 void setPriority(Priority prio);
00138
00139 Priority getPriority() const;
00141
00142 void start(Runnable& target);
00144
00145 void join();
00149
00150 void join(long milliseconds);
00154
00155 bool tryJoin(long milliseconds);
00159
00160 bool isRunning() const;
00162
00163 static void sleep(long milliseconds);
00166
00167 static void yield();
00169
00170 static Thread* current();
00173
00174 protected:
00175 ThreadLocalStorage& tls();
00177
00178 void clearTLS();
00180
00181 std::string makeName();
00183
00184 static int uniqueId();
00186
00187 private:
00188 Thread(const Thread&);
00189 Thread& operator = (const Thread&);
00190
00191 int _id;
00192 std::string _name;
00193 ThreadLocalStorage* _pTLS;
00194 mutable FastMutex _mutex;
00195
00196 friend class ThreadLocalStorage;
00197 friend class PooledThread;
00198 };
00199
00200
00201
00202
00203
00204 inline int Thread::id() const
00205 {
00206 return _id;
00207 }
00208
00209
00210 inline std::string Thread::name() const
00211 {
00212 FastMutex::ScopedLock lock(_mutex);
00213
00214 return _name;
00215 }
00216
00217
00218 inline std::string Thread::getName() const
00219 {
00220 FastMutex::ScopedLock lock(_mutex);
00221
00222 return _name;
00223 }
00224
00225
00226 inline bool Thread::isRunning() const
00227 {
00228 return isRunningImpl();
00229 }
00230
00231
00232 inline void Thread::sleep(long milliseconds)
00233 {
00234 sleepImpl(milliseconds);
00235 }
00236
00237
00238 inline void Thread::yield()
00239 {
00240 yieldImpl();
00241 }
00242
00243
00244 inline Thread* Thread::current()
00245 {
00246 return static_cast<Thread*>(currentImpl());
00247 }
00248
00249
00250 }
00251
00252
00253 #endif // Foundation_Thread_INCLUDED