diff options
Diffstat (limited to 'cpp/test/IceUtil/thread/MutexTest.cpp')
-rw-r--r-- | cpp/test/IceUtil/thread/MutexTest.cpp | 72 |
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(); |