summaryrefslogtreecommitdiff
path: root/cpp/test/IceUtil/thread/MutexTest.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2003-04-16 04:24:18 +0000
committerBernard Normier <bernard@zeroc.com>2003-04-16 04:24:18 +0000
commit3c99b3b3923f419eb3c2934fb017dadea6180fc6 (patch)
treec61d296def71d4c261637ef1297706883bf17d94 /cpp/test/IceUtil/thread/MutexTest.cpp
parenta link cost of 0 means accept all messages regardless of cost (diff)
downloadice-3c99b3b3923f419eb3c2934fb017dadea6180fc6.tar.bz2
ice-3c99b3b3923f419eb3c2934fb017dadea6180fc6.tar.xz
ice-3c99b3b3923f419eb3c2934fb017dadea6180fc6.zip
Mutex and Lock changes: lock/unlock now return void, trylock returns a bool
that indicates whether the lock was acquired or not, plus new member functions on LockT/TryLockT
Diffstat (limited to 'cpp/test/IceUtil/thread/MutexTest.cpp')
-rw-r--r--cpp/test/IceUtil/thread/MutexTest.cpp72
1 files changed, 59 insertions, 13 deletions
diff --git a/cpp/test/IceUtil/thread/MutexTest.cpp b/cpp/test/IceUtil/thread/MutexTest.cpp
index 77608a64c9d..4f7eb5c4b35 100644
--- a/cpp/test/IceUtil/thread/MutexTest.cpp
+++ b/cpp/test/IceUtil/thread/MutexTest.cpp
@@ -33,18 +33,14 @@ public:
}
virtual void run()
- {
- try
- {
- Mutex::TryLock lock(_mutex);
- test(false);
- }
- catch(const ThreadLockedException&)
+ {
+ Mutex::TryLock tlock(_mutex);
+ test(!tlock.acquired());
+
{
- // Expected
+ Mutex::Lock lock(_trylockMutex);
+ _trylock = true;
}
-
- _trylock = true;
_trylockCond.signal();
Mutex::Lock lock(_mutex);
@@ -87,11 +83,39 @@ MutexTest::run()
{
Mutex::Lock lock(mutex);
-
- // TEST: TryLock
+
+ // LockT testing:
+ //
+
+ test(lock.acquired());
+
try
{
- Mutex::TryLock lock2(mutex);
+ lock.acquire();
+ test(false);
+ }
+ catch(const ThreadLockedException&)
+ {
+ // Expected
+ }
+
+ try
+ {
+ lock.tryAcquire();
+ test(false);
+ }
+ catch(const ThreadLockedException&)
+ {
+ // Expected
+ }
+
+ test(lock.acquired());
+ lock.release();
+ test(!lock.acquired());
+
+ try
+ {
+ lock.release();
test(false);
}
catch(const ThreadLockedException&)
@@ -99,6 +123,28 @@ MutexTest::run()
// Expected
}
+ Mutex::TryLock lock2(mutex);
+ test(lock.tryAcquire() == false);
+ lock2.release();
+ test(lock.tryAcquire() == true);
+ test(lock.acquired());
+
+ // Deadlock testing
+ //
+
+#if !defined(NDEBUG) && !defined(_WIN32)
+ try
+ {
+ Mutex::Lock lock2(mutex);
+ test(false);
+ }
+ catch(const ThreadSyscallException& e)
+ {
+ // Expected
+ test(e.error() == EDEADLK);
+ }
+#endif
+
// TEST: Start thread, try to acquire the mutex.
t = new MutexTestThread(mutex);
control = t->start();