diff options
author | Michi Henning <michi@zeroc.com> | 2003-03-10 02:54:08 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2003-03-10 02:54:08 +0000 |
commit | 4be510ae7ab1c5a8542e73f06a4f5d5ccca8efd3 (patch) | |
tree | c10f8c70a540b70c5a3c3b1d45cd5e70b95e6c48 | |
parent | Added IceUtil::ThreadControl::isAlive() member function. (diff) | |
download | ice-4be510ae7ab1c5a8542e73f06a4f5d5ccca8efd3.tar.bz2 ice-4be510ae7ab1c5a8542e73f06a4f5d5ccca8efd3.tar.xz ice-4be510ae7ab1c5a8542e73f06a4f5d5ccca8efd3.zip |
Add ThreadControl::isAlive() functionality for Windows.
-rw-r--r-- | cpp/src/IceUtil/Thread.cpp | 16 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/AliveTest.cpp | 61 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/thread.dsp | 8 |
3 files changed, 69 insertions, 16 deletions
diff --git a/cpp/src/IceUtil/Thread.cpp b/cpp/src/IceUtil/Thread.cpp index cab9cddfa95..4994079002a 100644 --- a/cpp/src/IceUtil/Thread.cpp +++ b/cpp/src/IceUtil/Thread.cpp @@ -89,6 +89,22 @@ IceUtil::ThreadControl::detach() _detached = true; } } +
+bool
+IceUtil::ThreadControl::isAlive() const
+{
+ if(!_handle->handle)
+ {
+ return false;
+ }
+
+ DWORD rc;
+ if(GetExitCodeThread(_handle->handle, &rc) == 0)
+ {
+ return false;
+ }
+ return rc == STILL_ACTIVE;
+}
void IceUtil::ThreadControl::sleep(const Time& timeout) diff --git a/cpp/test/IceUtil/thread/AliveTest.cpp b/cpp/test/IceUtil/thread/AliveTest.cpp index d1b8e3ea48a..63c4db28100 100644 --- a/cpp/test/IceUtil/thread/AliveTest.cpp +++ b/cpp/test/IceUtil/thread/AliveTest.cpp @@ -15,7 +15,6 @@ #include <IceUtil/IceUtil.h> #include <stdio.h> -#include <unistd.h> #include <AliveTest.h> #include <TestCommon.h> @@ -23,21 +22,48 @@ using namespace std; using namespace IceUtil; -static const string createTestName("thread alive"); +static const string createTestName("thread alive");
+
+class Synchronizer : public IceUtil::Monitor<IceUtil::Mutex>
+{
+public:
+ Synchronizer() : _done(false)
+ {
+ }
+
+ void p()
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
+ while (!_done)
+ {
+ wait();
+ }
+ }
+
+ void v()
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
+ _done = true;
+ notify();
+ }
+
+private:
+ bool _done;
+}; class AliveTestThread : public Thread { -public: - - AliveTestThread(IceUtil::RWRecMutex& m) : _m(m) - { - } +public:
+ AliveTestThread(Synchronizer& child, Synchronizer& parent) : _child(child), _parent(parent)
+ {
+ }
virtual void run() { try - { - IceUtil::RWRecMutex::TryWLock lock(_m, IceUtil::Time::seconds(1)); + {
+ _child.v();
+ _parent.p(); } catch(IceUtil::ThreadLockedException &) { @@ -45,7 +71,8 @@ public: } private: - RWRecMutex& _m; + Synchronizer& _child;
+ Synchronizer& _parent; }; typedef Handle<AliveTestThread> AliveTestThreadPtr; @@ -61,12 +88,14 @@ AliveTest::run() // // Check that calling isAlive() returns the correct result for alive and // and dead threads. - // - IceUtil::RWRecMutex m; - m.writelock(); - AliveTestThreadPtr t = new AliveTestThread(m); - IceUtil::ThreadControl c = t->start(); - test(c.isAlive()); + //
+ Synchronizer parentReady;
+ Synchronizer childReady; + AliveTestThreadPtr t = new AliveTestThread(childReady, parentReady); + IceUtil::ThreadControl c = t->start();
+ childReady.p();
+ test(c.isAlive());
+ parentReady.v(); c.join(); test(!c.isAlive()); } diff --git a/cpp/test/IceUtil/thread/thread.dsp b/cpp/test/IceUtil/thread/thread.dsp index 088710feaeb..bf00c1a8c8c 100644 --- a/cpp/test/IceUtil/thread/thread.dsp +++ b/cpp/test/IceUtil/thread/thread.dsp @@ -91,6 +91,10 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
+SOURCE=.\AliveTest.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\Client.cpp
# End Source File
# Begin Source File
@@ -139,6 +143,10 @@ SOURCE=.\TestSuite.cpp # PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
+SOURCE=.\AliveTest.h
+# End Source File
+# Begin Source File
+
SOURCE=.\CreateTest.h
# End Source File
# Begin Source File
|