summaryrefslogtreecommitdiff
path: root/cppe/test/IceE/thread/RecMutexTest.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2005-07-05 11:09:55 +0000
committerDwayne Boone <dwayne@zeroc.com>2005-07-05 11:09:55 +0000
commit9b8cc712d4a41d71840416776bc94ee8485bb9b3 (patch)
tree7d467fdd6a66bc2b5878d82070d45adbd5c20414 /cppe/test/IceE/thread/RecMutexTest.cpp
parentcleaning the cache method out of ReferenceFactory (diff)
downloadice-9b8cc712d4a41d71840416776bc94ee8485bb9b3.tar.bz2
ice-9b8cc712d4a41d71840416776bc94ee8485bb9b3.tar.xz
ice-9b8cc712d4a41d71840416776bc94ee8485bb9b3.zip
Changed Ice to IceE EVERYWHERE!!!
Diffstat (limited to 'cppe/test/IceE/thread/RecMutexTest.cpp')
-rw-r--r--cppe/test/IceE/thread/RecMutexTest.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/cppe/test/IceE/thread/RecMutexTest.cpp b/cppe/test/IceE/thread/RecMutexTest.cpp
new file mode 100644
index 00000000000..2bb63d90549
--- /dev/null
+++ b/cppe/test/IceE/thread/RecMutexTest.cpp
@@ -0,0 +1,106 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceE/IceE.h>
+
+#include <RecMutexTest.h>
+#include <TestCommon.h>
+
+using namespace std;
+using namespace IceE;
+
+static const string recMutexTestName("recursive mutex");
+
+class RecMutexTestThread : public Thread
+{
+public:
+
+ RecMutexTestThread(RecMutex& m) :
+ _mutex(m),
+ _tryLock(false)
+ {
+ }
+
+ virtual void run()
+ {
+
+ RecMutex::TryLock tlock(_mutex);
+ test(!tlock.acquired());
+
+ {
+ Mutex::Lock lock(_tryLockMutex);
+ _tryLock = true;
+ }
+ _tryLockCond.signal();
+
+ RecMutex::Lock lock(_mutex);
+ }
+
+ void
+ waitTryLock()
+ {
+ Mutex::Lock lock(_tryLockMutex);
+ while(!_tryLock)
+ {
+ _tryLockCond.wait(lock);
+ }
+ }
+
+private:
+
+ RecMutex& _mutex;
+ bool _tryLock;
+ //
+ // Use native Condition variable here, not Monitor.
+ //
+ Cond _tryLockCond;
+ Mutex _tryLockMutex;
+};
+
+typedef Handle<RecMutexTestThread> RecMutexTestThreadPtr;
+
+RecMutexTest::RecMutexTest() :
+ TestBase(recMutexTestName)
+{
+}
+
+void
+RecMutexTest::run()
+{
+ RecMutex mutex;
+ RecMutexTestThreadPtr t;
+ ThreadControl control;
+
+ {
+ RecMutex::Lock lock(mutex);
+
+ // TEST: lock twice
+ RecMutex::Lock lock2(mutex);
+
+ // TEST: TryLock
+ RecMutex::TryLock lock3(mutex);
+ test(lock3.acquired());
+
+ // TEST: Start thread, try to acquire the mutex.
+ t = new RecMutexTestThread(mutex);
+ control = t->start();
+
+ // TEST: Wait until the tryLock has been tested.
+ t->waitTryLock();
+
+ }
+
+ //
+ // TEST: Once the recursive mutex has been released, the thread
+ // should acquire the mutex and then terminate.
+ //
+
+ control.join();
+
+}