summaryrefslogtreecommitdiff
path: root/cpp/test/IceUtil/thread/RWRecMutexTest.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/RWRecMutexTest.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/RWRecMutexTest.cpp')
-rw-r--r--cpp/test/IceUtil/thread/RWRecMutexTest.cpp154
1 files changed, 80 insertions, 74 deletions
diff --git a/cpp/test/IceUtil/thread/RWRecMutexTest.cpp b/cpp/test/IceUtil/thread/RWRecMutexTest.cpp
index 5fc5db11c7a..916f0fa3fa4 100644
--- a/cpp/test/IceUtil/thread/RWRecMutexTest.cpp
+++ b/cpp/test/IceUtil/thread/RWRecMutexTest.cpp
@@ -66,17 +66,13 @@ public:
virtual void
run()
{
- try
+ RWRecMutex::TryRLock tlock(_mutex);
+ test(tlock.acquired());
+
{
- RWRecMutex::TryRLock lock(_mutex);
- // Expected
+ Mutex::Lock lock(_trylockMutex);
+ _trylock = true;
}
- catch(const ThreadLockedException&)
- {
- test(false);
- }
-
- _trylock = true;
_trylockCond.signal();
RWRecMutex::RLock lock(_mutex);
@@ -95,17 +91,14 @@ public:
virtual void
run()
{
- try
- {
- RWRecMutex::TryRLock lock(_mutex);
- test(false);
- }
- catch(const ThreadLockedException&)
+
+ RWRecMutex::TryRLock tlock(_mutex);
+ test(!tlock.acquired());
+
{
- // Expected
+ Mutex::Lock lock(_trylockMutex);
+ _trylock = true;
}
-
- _trylock = true;
_trylockCond.signal();
RWRecMutex::RLock lock(_mutex);
@@ -257,17 +250,14 @@ public:
virtual void
run()
{
- try
- {
- RWRecMutex::TryWLock lock(_mutex);
- test(false);
- }
- catch(const ThreadLockedException&)
+
+ RWRecMutex::TryWLock tlock(_mutex);
+ test(!tlock.acquired());
+
{
- // Expected
+ Mutex::Lock lock(_trylockMutex);
+ _trylock = true;
}
-
- _trylock = true;
_trylockCond.signal();
RWRecMutex::WLock lock(_mutex);
@@ -290,20 +280,23 @@ RWRecMutexTest::run()
// TEST: TryLock (read)
{
RWRecMutex::RLock rlock(mutex);
- RWRecMutex::RLock rlock2(mutex);
+ // RLock testing
+ test(rlock.acquired());
+
try
{
- RWRecMutex::TryRLock rlock2(mutex);
+ rlock.acquire();
+ test(false);
}
catch(const ThreadLockedException&)
{
- test(false);
+ // Expected
}
try
{
- RWRecMutex::TryWLock wlock(mutex);
+ rlock.tryAcquire();
test(false);
}
catch(const ThreadLockedException&)
@@ -311,58 +304,90 @@ RWRecMutexTest::run()
// Expected
}
+ test(rlock.acquired());
+ rlock.release();
+ test(!rlock.acquired());
+
try
{
- RWRecMutex::TryWLock wlock(mutex, Time::milliSeconds(10));
+ rlock.release();
test(false);
}
catch(const ThreadLockedException&)
{
// Expected
}
+
+ test(rlock.tryAcquire() == true);
+ test(rlock.acquired());
+
+ RWRecMutex::RLock rlock2(mutex);
+
+ RWRecMutex::TryRLock trlock(mutex);
+ test(trlock.acquired());
+
+ RWRecMutex::TryWLock twlock(mutex);
+ test(!twlock.acquired());
+
+ RWRecMutex::TryWLock twlock2(mutex, Time::milliSeconds(10));
+ test(!twlock2.acquired());
}
// TEST: TryLock (write)
{
RWRecMutex::WLock wlock(mutex);
+
+ // WLock testing
+ test(wlock.acquired());
- // TEST: TryLock
try
{
- RWRecMutex::TryRLock rlock(mutex);
+ wlock.acquire();
test(false);
}
catch(const ThreadLockedException&)
{
// Expected
}
+
try
{
- RWRecMutex::TryRLock rlock(mutex, Time::milliSeconds(10));
+ wlock.tryAcquire();
test(false);
}
catch(const ThreadLockedException&)
{
// Expected
}
+
+ test(wlock.acquired());
+ wlock.release();
+ test(!wlock.acquired());
+
try
{
- RWRecMutex::TryWLock wlock(mutex);
- // Expected
- }
- catch(const ThreadLockedException&)
- {
+ wlock.release();
test(false);
}
- try
- {
- RWRecMutex::TryWLock wlock(mutex, Time::milliSeconds(10));
- // Expected
- }
catch(const ThreadLockedException&)
{
- test(false);
+ // Expected
}
+
+ test(wlock.tryAcquire() == true);
+ test(wlock.acquired());
+
+ RWRecMutex::TryRLock trlock(mutex);
+ test(!trlock.acquired());
+
+ RWRecMutex::TryRLock trlock2(mutex, Time::milliSeconds(10));
+ test(!trlock2.acquired());
+
+ RWRecMutex::TryWLock twlock(mutex);
+ test(twlock.acquired());
+
+ RWRecMutex::TryWLock twlock2(mutex, Time::milliSeconds(10));
+ test(twlock2.acquired());
}
// TEST: read lock
@@ -417,15 +442,8 @@ RWRecMutexTest::run()
// thread is actually waiting on a write lock.
ThreadControl::sleep(Time::seconds(1));
- try
- {
- RWRecMutex::TryRLock rlock2(mutex);
- test(false);
- }
- catch(const ThreadLockedException&)
- {
- // Expected
- }
+ RWRecMutex::TryRLock trlock(mutex);
+ test(!trlock.acquired());
}
//
@@ -495,29 +513,17 @@ RWRecMutexTest::run()
//
// A read lock at this point should fail.
//
- try
- {
- RWRecMutex::TryRLock rlock2(mutex);
- test(false);
- }
- catch(const ThreadLockedException&)
- {
- // Expected
- }
+ RWRecMutex::TryRLock trlock(mutex);
+ test(!trlock.acquired());
+
//
// As should a write lock.
//
- try
- {
- RWRecMutex::TryWLock rlock2(mutex);
- test(false);
- }
- catch(const ThreadLockedException&)
- {
- // Expected
- }
-
+
+ RWRecMutex::TryWLock twlock(mutex);
+ test(!twlock.acquired());
+
//
// Once the read lock is released then the upgrade should
// succeed & the thread should terminate.