diff options
author | Matthew Newhook <matthew@zeroc.com> | 2006-03-02 08:48:09 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2006-03-02 08:48:09 +0000 |
commit | 7da502a811dab261a851fca83545e64ceb985721 (patch) | |
tree | 06ca0aef3feeb3cfdc744acc2dd590b479d1237d /cppe/include/IceE/Thread.h | |
parent | requires STLport 5.0.2 (diff) | |
download | ice-7da502a811dab261a851fca83545e64ceb985721.tar.bz2 ice-7da502a811dab261a851fca83545e64ceb985721.tar.xz ice-7da502a811dab261a851fca83545e64ceb985721.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=824
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=725
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=724
Diffstat (limited to 'cppe/include/IceE/Thread.h')
-rw-r--r-- | cppe/include/IceE/Thread.h | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/cppe/include/IceE/Thread.h b/cppe/include/IceE/Thread.h index 38fbfa448a1..db2b2ed420f 100644 --- a/cppe/include/IceE/Thread.h +++ b/cppe/include/IceE/Thread.h @@ -19,7 +19,7 @@ namespace IceUtil class Time; -#ifdef _WIN32 +#ifdef _WIN32_WCE struct HandleWrapper : public Shared { // Inline for performance reasons. @@ -40,18 +40,9 @@ struct HandleWrapper : public Shared HANDLE handle; bool release; }; - typedef Handle<HandleWrapper> HandleWrapperPtr; #endif -#ifdef _WIN32_WCE - typedef unsigned long ThreadId; -#elif _WIN32 - typedef unsigned int ThreadId; -#else - typedef pthread_t ThreadId; -#endif - class ICE_API ThreadControl { public: @@ -59,9 +50,9 @@ public: ThreadControl(); #ifdef _WIN32 - ThreadControl(const HandleWrapperPtr&, ThreadId); + ThreadControl(const HandleWrapperPtr&, DWORD); #else - ThreadControl(ThreadId); + ThreadControl(pthread_t); #endif ThreadControl(const ThreadControl&); @@ -69,12 +60,6 @@ public: bool operator==(const ThreadControl&) const; bool operator!=(const ThreadControl&) const; - bool operator<(const ThreadControl&) const; - - // - // Return the ID of the thread underlying this ThreadControl. - // - ThreadId id() const; // // Wait until the controlled thread terminates. The call has POSIX @@ -99,21 +84,27 @@ public: void detach(); // - // Check whether a thread is still alive. This is useful to implement - // a non-blocking join(). + // id() returns the Thread ID on Windows and the underlying pthread_t + // on POSIX platforms. // - bool isAlive() const; +#ifdef _WIN32 + typedef DWORD ID; +#else + typedef pthread_t ID; +#endif + ID id() const; static void sleep(const Time&); static void yield(); private: - Mutex _stateMutex; #ifdef _WIN32 + DWORD _id; HandleWrapperPtr _handle; +#else + pthread_t _thread; #endif - ThreadId _id; }; class ICE_API Thread : virtual public IceUtil::Shared @@ -123,8 +114,6 @@ public: Thread(); virtual ~Thread(); - ThreadId id() const; - virtual void run() = 0; ThreadControl start(size_t = 0); @@ -135,17 +124,33 @@ public: bool operator!=(const Thread&) const; bool operator<(const Thread&) const; - Thread(const Thread&); // Copying is forbidden - void operator=(const Thread&); // Assignment is forbidden + // + // Check whether a thread is still alive. This is useful to implement + // a non-blocking join(). + // + bool isAlive() const; -private: + // + // This function is an implementation detail; + // do not call it. + // + void _done(); + +protected: Mutex _stateMutex; bool _started; + bool _running; + #ifdef _WIN32 HandleWrapperPtr _handle; + DWORD _id; +#else + pthread_t _thread; #endif - ThreadId _id; + + Thread(const Thread&); // Copying is forbidden + void operator=(const Thread&); // Assignment is forbidden }; typedef Handle<Thread> ThreadPtr; |