diff options
author | Bernard Normier <bernard@zeroc.com> | 2006-01-30 23:43:05 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2006-01-30 23:43:05 +0000 |
commit | c0657e9d3824d1585fce92d051ca9684552272c2 (patch) | |
tree | 7e4075efbf16f268fd862e8125940c4646220aef /cpp/include/IceUtil/Thread.h | |
parent | Reenabled unicode test (diff) | |
download | ice-c0657e9d3824d1585fce92d051ca9684552272c2.tar.bz2 ice-c0657e9d3824d1585fce92d051ca9684552272c2.tar.xz ice-c0657e9d3824d1585fce92d051ca9684552272c2.zip |
Fixed bugs 724 and 725
Diffstat (limited to 'cpp/include/IceUtil/Thread.h')
-rw-r--r-- | cpp/include/IceUtil/Thread.h | 70 |
1 files changed, 19 insertions, 51 deletions
diff --git a/cpp/include/IceUtil/Thread.h b/cpp/include/IceUtil/Thread.h index 03f0304aba5..bd7fbcfee7d 100644 --- a/cpp/include/IceUtil/Thread.h +++ b/cpp/include/IceUtil/Thread.h @@ -19,37 +19,6 @@ 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 - -#ifdef _WIN32 - typedef unsigned int ThreadId; -#else - typedef pthread_t ThreadId; -#endif - class ICE_UTIL_API ThreadControl { public: @@ -57,22 +26,19 @@ public: ThreadControl(); #ifdef _WIN32 - ThreadControl(const HandleWrapperPtr&, ThreadId); + ThreadControl(HANDLE, DWORD); #else - ThreadControl(ThreadId); + ThreadControl(pthread_t); #endif ThreadControl(const ThreadControl&); + + ~ThreadControl(); + ThreadControl& operator=(const ThreadControl&); 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 @@ -107,11 +73,12 @@ public: private: - Mutex _stateMutex; #ifdef _WIN32 - HandleWrapperPtr _handle; + HANDLE _handle; + DWORD _id; +#else + pthread_t _thread; #endif - ThreadId _id; }; class ICE_UTIL_API Thread : virtual public IceUtil::Shared @@ -121,8 +88,6 @@ public: Thread(); virtual ~Thread(); - ThreadId id() const; - virtual void run() = 0; ThreadControl start(size_t = 0); @@ -133,17 +98,20 @@ public: bool operator!=(const Thread&) const; bool operator<(const Thread&) const; - Thread(const Thread&); // Copying is forbidden - void operator=(const Thread&); // Assignment is forbidden - -private: - +protected: Mutex _stateMutex; + bool _started; #ifdef _WIN32 - HandleWrapperPtr _handle; + HANDLE _handle; + DWORD _id; +#else + pthread_t _thread; #endif - ThreadId _id; + +private: + Thread(const Thread&); // Copying is forbidden + void operator=(const Thread&); // Assignment is forbidden }; typedef Handle<Thread> ThreadPtr; |