diff options
author | Bernard Normier <bernard@zeroc.com> | 2006-03-03 16:46:52 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2006-03-03 16:46:52 +0000 |
commit | d177e80729ded6ca60fdcc5cd91810fcc17c05dc (patch) | |
tree | 0a4ad010ec0eb3a19884a5b76519db07df13b816 /cppe/include/IceE/Thread.h | |
parent | fixed build failure (diff) | |
download | ice-d177e80729ded6ca60fdcc5cd91810fcc17c05dc.tar.bz2 ice-d177e80729ded6ca60fdcc5cd91810fcc17c05dc.tar.xz ice-d177e80729ded6ca60fdcc5cd91810fcc17c05dc.zip |
Better fix for bug #824
Diffstat (limited to 'cppe/include/IceE/Thread.h')
-rw-r--r-- | cppe/include/IceE/Thread.h | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/cppe/include/IceE/Thread.h b/cppe/include/IceE/Thread.h index 031010ef90e..f966bfac639 100644 --- a/cppe/include/IceE/Thread.h +++ b/cppe/include/IceE/Thread.h @@ -19,45 +19,30 @@ namespace IceUtil class Time; -#ifdef _WIN32 -struct HandleWrapper : public Shared -{ - // Inline for performance reasons. - HandleWrapper(HANDLE h, bool r = true) : - handle(h), release(r) - { - } - - // Inline for performance reasons. - virtual ~HandleWrapper() - { - if(handle && release) - { - CloseHandle(handle); - } - } - - HANDLE handle; - bool release; -}; -typedef Handle<HandleWrapper> HandleWrapperPtr; -#endif - class ICE_API ThreadControl { public: + // + // Constructs a ThreadControl representing the current thread. + // join and detach cannot be called on such ThreadControl object. + // ThreadControl(); #ifdef _WIN32 - ThreadControl(const HandleWrapperPtr&, DWORD); + ThreadControl(HANDLE, DWORD); #else ThreadControl(pthread_t); #endif - ThreadControl(const ThreadControl&); - ThreadControl& operator=(const ThreadControl&); + // + // Default copy destructor, assignment operator and destructor OK + // + // + // == and != are meaningful only before the thread is joined/detached, + // or while the thread is still running. + // bool operator==(const ThreadControl&) const; bool operator!=(const ThreadControl&) const; @@ -100,10 +85,17 @@ public: private: #ifdef _WIN32 - DWORD _id; - HandleWrapperPtr _handle; + HANDLE _handle; + DWORD _id; #else pthread_t _thread; + + // + // Used to prevent joining/detaching a ThreadControl constructed + // with the default constructor. Only needed to enforce our + // portable join/detach behavior. + // + bool _detachable; #endif }; @@ -125,8 +117,7 @@ public: bool operator<(const Thread&) const; // - // Check whether a thread is still alive. This is useful to implement - // a non-blocking join(). + // Check whether a thread is still alive. // bool isAlive() const; @@ -136,19 +127,19 @@ public: // void _done(); - protected: Mutex _stateMutex; bool _started; bool _running; #ifdef _WIN32 - HandleWrapperPtr _handle; - DWORD _id; + HANDLE _handle; + DWORD _id; #else pthread_t _thread; #endif +private: Thread(const Thread&); // Copying is forbidden void operator=(const Thread&); // Assignment is forbidden }; |