diff options
author | Bernard Normier <bernard@zeroc.com> | 2003-05-16 15:38:25 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2003-05-16 15:38:25 +0000 |
commit | f80e2c27c6b4deb05e4e533092dd90dd449262d1 (patch) | |
tree | e1dc25bfe5c122976677b2a3bcfce6d1ab3683bd /cpp | |
parent | all timed function now return false on timeout instead of raising an (diff) | |
download | ice-f80e2c27c6b4deb05e4e533092dd90dd449262d1.tar.bz2 ice-f80e2c27c6b4deb05e4e533092dd90dd449262d1.tar.xz ice-f80e2c27c6b4deb05e4e533092dd90dd449262d1.zip |
Renamed trylock, readlock and writelock to tryLock, readLock and writeLock
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/CHANGES | 6 | ||||
-rw-r--r-- | cpp/include/IceUtil/Lock.h | 6 | ||||
-rw-r--r-- | cpp/include/IceUtil/Monitor.h | 8 | ||||
-rw-r--r-- | cpp/include/IceUtil/Mutex.h | 8 | ||||
-rw-r--r-- | cpp/include/IceUtil/RWRecMutex.h | 38 | ||||
-rw-r--r-- | cpp/include/IceUtil/RecMutex.h | 4 | ||||
-rw-r--r-- | cpp/include/IceUtil/StaticMutex.h | 8 | ||||
-rw-r--r-- | cpp/src/IceUtil/RWRecMutex.cpp | 12 | ||||
-rw-r--r-- | cpp/src/IceUtil/RecMutex.cpp | 4 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/MonitorMutexTest.cpp | 26 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp | 26 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/MutexTest.cpp | 26 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/RWRecMutexTest.cpp | 50 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/RecMutexTest.cpp | 26 |
14 files changed, 127 insertions, 121 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index f0dc6013803..add39250fcb 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -1,6 +1,12 @@ Changes since version 1.0.1 --------------------------- +- In IceUtil, all try and timed function now return false when the + resource could not be acquired (an expected failure). + The 'Try' from timedTry functions was removed, and for consistency + trylock, readlock and writelock functions were renamed tryLock, + readLock and writeLock. + - Update to the library versioning scheme: On Windows, only the major and minor version are now used, for diff --git a/cpp/include/IceUtil/Lock.h b/cpp/include/IceUtil/Lock.h index fa13340ae94..9d466b1a1b6 100644 --- a/cpp/include/IceUtil/Lock.h +++ b/cpp/include/IceUtil/Lock.h @@ -27,7 +27,7 @@ namespace IceUtil class Cond; -// LockT and TryLockT are the preferred construct to lock/trylock/unlock +// LockT and TryLockT are the preferred construct to lock/tryLock/unlock // simple and recursive mutexes. You typically allocate them on the // stack to hold a lock on a mutex. // LockT and TryLockT are not recursive: you cannot acquire several times @@ -80,7 +80,7 @@ public: { throw ThreadLockedException(__FILE__, __LINE__); } - _acquired = _mutex.trylock(); + _acquired = _mutex.tryLock(); return _acquired; } @@ -105,7 +105,7 @@ protected: LockT(const T& mutex, bool) : _mutex(mutex) { - _acquired = _mutex.trylock(); + _acquired = _mutex.tryLock(); } private: diff --git a/cpp/include/IceUtil/Monitor.h b/cpp/include/IceUtil/Monitor.h index 1c6bd53b29e..bdb1e02039c 100644 --- a/cpp/include/IceUtil/Monitor.h +++ b/cpp/include/IceUtil/Monitor.h @@ -39,12 +39,12 @@ public: ~Monitor(); // - // Note that lock/trylock & unlock in general should not be used + // Note that lock/tryLock & unlock in general should not be used // directly. Instead use Lock & TryLock. // void lock() const; void unlock() const; - bool trylock() const; + bool tryLock() const; void wait() const; bool timedWait(const Time&) const; @@ -127,9 +127,9 @@ IceUtil::Monitor<T>::unlock() const } template <class T> inline bool -IceUtil::Monitor<T>::trylock() const +IceUtil::Monitor<T>::tryLock() const { - bool result = _mutex.trylock(); + bool result = _mutex.tryLock(); if(result && _mutex.willUnlock()) { // diff --git a/cpp/include/IceUtil/Mutex.h b/cpp/include/IceUtil/Mutex.h index 592a9236c0c..186070db2f2 100644 --- a/cpp/include/IceUtil/Mutex.h +++ b/cpp/include/IceUtil/Mutex.h @@ -51,7 +51,7 @@ public: ~Mutex(); // - // Note that lock/trylock & unlock in general should not be used + // Note that lock/tryLock & unlock in general should not be used // directly. Instead use Lock & TryLock. // @@ -60,7 +60,7 @@ public: // // Returns true if the lock was acquired, and false otherwise. // - bool trylock() const; + bool tryLock() const; void unlock() const; @@ -138,7 +138,7 @@ Mutex::lock() const } inline bool -Mutex::trylock() const +Mutex::tryLock() const { if(!TryEnterCriticalSection(&_mutex)) { @@ -225,7 +225,7 @@ Mutex::lock() const } inline bool -Mutex::trylock() const +Mutex::tryLock() const { int rc = pthread_mutex_trylock(&_mutex); if(rc != 0 && rc != EBUSY) diff --git a/cpp/include/IceUtil/RWRecMutex.h b/cpp/include/IceUtil/RWRecMutex.h index 2fad8fa4227..eb1e9df51f6 100644 --- a/cpp/include/IceUtil/RWRecMutex.h +++ b/cpp/include/IceUtil/RWRecMutex.h @@ -30,7 +30,7 @@ public: RLockT(const T& mutex) : _mutex(mutex) { - _mutex.readlock(); + _mutex.readLock(); _acquired = true; } @@ -48,7 +48,7 @@ public: { throw ThreadLockedException(__FILE__, __LINE__); } - _mutex.readlock(); + _mutex.readLock(); _acquired = true; } @@ -58,7 +58,7 @@ public: { throw ThreadLockedException(__FILE__, __LINE__); } - _acquired = _mutex.tryReadlock(); + _acquired = _mutex.tryReadLock(); return _acquired; } @@ -68,7 +68,7 @@ public: { throw ThreadLockedException(__FILE__, __LINE__); } - _acquired = _mutex.timedTryReadlock(timeout); + _acquired = _mutex.timedReadLock(timeout); return _acquired; } @@ -108,14 +108,14 @@ protected: RLockT(const T& mutex, bool) : _mutex(mutex) { - _acquired = _mutex.tryReadlock(); + _acquired = _mutex.tryReadLock(); } RLockT(const T& mutex, const Time& timeout) : _mutex(mutex) { - _acquired = _mutex.timedReadlock(timeout); + _acquired = _mutex.timedReadLock(timeout); } @@ -154,7 +154,7 @@ public: WLockT(const T& mutex) : _mutex(mutex) { - _mutex.writelock(); + _mutex.writeLock(); _acquired = true; } @@ -172,7 +172,7 @@ public: { throw ThreadLockedException(__FILE__, __LINE__); } - _mutex.writelock(); + _mutex.writeLock(); _acquired = true; } @@ -182,7 +182,7 @@ public: { throw ThreadLockedException(__FILE__, __LINE__); } - _acquired = _mutex.tryWritelock(); + _acquired = _mutex.tryWriteLock(); return _acquired; } @@ -192,7 +192,7 @@ public: { throw ThreadLockedException(__FILE__, __LINE__); } - _acquired = _mutex.timedTryWritelock(timeout); + _acquired = _mutex.timedWriteLock(timeout); return _acquired; } @@ -218,13 +218,13 @@ protected: WLockT(const T& mutex, bool) : _mutex(mutex) { - _acquired = _mutex.tryWritelock(); + _acquired = _mutex.tryWriteLock(); } WLockT(const T& mutex, const Time& timeout) : _mutex(mutex) { - _acquired = _mutex.timedWritelock(timeout); + _acquired = _mutex.timedWriteLock(timeout); } private: @@ -280,39 +280,39 @@ public: ~RWRecMutex(); // - // Note that readlock/writelock & unlock in general should not be + // Note that readLock/writeLock & unlock in general should not be // used directly. Instead use RLock & WLock. // // // Acquire a read lock. // - void readlock() const; + void readLock() const; // // Try to acquire a read lock. // - bool tryReadlock() const; + bool tryReadLock() const; // // Try to acquire a read lock for upto the given timeout. // - bool timedReadlock(const Time&) const; + bool timedReadLock(const Time&) const; // // Acquire a write lock. // - void writelock() const; + void writeLock() const; // // Acquire a write lock. // - bool tryWritelock() const; + bool tryWriteLock() const; // // Acquire a write lock for up to the given timeout. // - bool timedWritelock(const Time&) const; + bool timedWriteLock(const Time&) const; // // Unlock the reader/writer lock. diff --git a/cpp/include/IceUtil/RecMutex.h b/cpp/include/IceUtil/RecMutex.h index 12c00c368a6..dc210529662 100644 --- a/cpp/include/IceUtil/RecMutex.h +++ b/cpp/include/IceUtil/RecMutex.h @@ -44,7 +44,7 @@ public: ~RecMutex(); // - // Note that lock/trylock & unlock in general should not be used + // Note that lock/tryLock & unlock in general should not be used // directly. Instead use Lock & TryLock. // @@ -53,7 +53,7 @@ public: // // Returns true if the lock was acquired, and false otherwise. // - bool trylock() const; + bool tryLock() const; void unlock() const; diff --git a/cpp/include/IceUtil/StaticMutex.h b/cpp/include/IceUtil/StaticMutex.h index 036bafd8d59..df16e103195 100644 --- a/cpp/include/IceUtil/StaticMutex.h +++ b/cpp/include/IceUtil/StaticMutex.h @@ -45,7 +45,7 @@ public: typedef TryLockT<StaticMutex> TryLock; // - // Note that lock/trylock & unlock in general should not be used + // Note that lock/tryLock & unlock in general should not be used // directly. Instead use Lock & TryLock. // @@ -54,7 +54,7 @@ public: // // Returns true if the lock was acquired, and false otherwise. // - bool trylock() const; + bool tryLock() const; void unlock() const; @@ -137,7 +137,7 @@ StaticMutex::lock() const } inline bool -StaticMutex::trylock() const +StaticMutex::tryLock() const { if (!_mutexInitialized) { @@ -193,7 +193,7 @@ StaticMutex::lock() const } inline bool -StaticMutex::trylock() const +StaticMutex::tryLock() const { int rc = pthread_mutex_trylock(&_mutex); if(rc != 0 && rc != EBUSY) diff --git a/cpp/src/IceUtil/RWRecMutex.cpp b/cpp/src/IceUtil/RWRecMutex.cpp index 5a8bea627b4..c396f2b1a3a 100644 --- a/cpp/src/IceUtil/RWRecMutex.cpp +++ b/cpp/src/IceUtil/RWRecMutex.cpp @@ -29,7 +29,7 @@ IceUtil::RWRecMutex::~RWRecMutex() } void -IceUtil::RWRecMutex::readlock() const +IceUtil::RWRecMutex::readLock() const { Mutex::Lock lock(_mutex); @@ -45,7 +45,7 @@ IceUtil::RWRecMutex::readlock() const } bool -IceUtil::RWRecMutex::tryReadlock() const +IceUtil::RWRecMutex::tryReadLock() const { Mutex::Lock lock(_mutex); @@ -62,7 +62,7 @@ IceUtil::RWRecMutex::tryReadlock() const } bool -IceUtil::RWRecMutex::timedReadlock(const Time& timeout) const +IceUtil::RWRecMutex::timedReadLock(const Time& timeout) const { Mutex::Lock lock(_mutex); @@ -92,7 +92,7 @@ IceUtil::RWRecMutex::timedReadlock(const Time& timeout) const } void -IceUtil::RWRecMutex::writelock() const +IceUtil::RWRecMutex::writeLock() const { Mutex::Lock lock(_mutex); @@ -133,7 +133,7 @@ IceUtil::RWRecMutex::writelock() const } bool -IceUtil::RWRecMutex::tryWritelock() const +IceUtil::RWRecMutex::tryWriteLock() const { Mutex::Lock lock(_mutex); @@ -164,7 +164,7 @@ IceUtil::RWRecMutex::tryWritelock() const } bool -IceUtil::RWRecMutex::timedWritelock(const Time& timeout) const +IceUtil::RWRecMutex::timedWriteLock(const Time& timeout) const { Mutex::Lock lock(_mutex); diff --git a/cpp/src/IceUtil/RecMutex.cpp b/cpp/src/IceUtil/RecMutex.cpp index 44f81a0ca59..0addcc0f61f 100644 --- a/cpp/src/IceUtil/RecMutex.cpp +++ b/cpp/src/IceUtil/RecMutex.cpp @@ -42,7 +42,7 @@ IceUtil::RecMutex::lock() const } bool -IceUtil::RecMutex::trylock() const +IceUtil::RecMutex::tryLock() const { if(!TryEnterCriticalSection(&_mutex)) { @@ -142,7 +142,7 @@ IceUtil::RecMutex::lock() const } bool -IceUtil::RecMutex::trylock() const +IceUtil::RecMutex::tryLock() const { int rc = pthread_mutex_trylock(&_mutex); bool result = (rc == 0); diff --git a/cpp/test/IceUtil/thread/MonitorMutexTest.cpp b/cpp/test/IceUtil/thread/MonitorMutexTest.cpp index 7d04267abef..9e8c6a660ef 100644 --- a/cpp/test/IceUtil/thread/MonitorMutexTest.cpp +++ b/cpp/test/IceUtil/thread/MonitorMutexTest.cpp @@ -26,7 +26,7 @@ public: MonitorMutexTestThread(Monitor<Mutex>& m) : _monitor(m), - _trylock(false) + _tryLock(false) { } @@ -36,33 +36,33 @@ public: test(!tlock.acquired()); { - Mutex::Lock lock(_trylockMutex); - _trylock = true; + Mutex::Lock lock(_tryLockMutex); + _tryLock = true; } - _trylockCond.signal(); + _tryLockCond.signal(); Monitor<Mutex>::Lock lock(_monitor); } void - waitTrylock() + waitTryLock() { - Mutex::Lock lock(_trylockMutex); - while(!_trylock) + Mutex::Lock lock(_tryLockMutex); + while(!_tryLock) { - _trylockCond.wait(lock); + _tryLockCond.wait(lock); } } private: Monitor<Mutex>& _monitor; - bool _trylock; + bool _tryLock; // // Use native Condition variable here, not Monitor. // - Cond _trylockCond; - Mutex _trylockMutex; + Cond _tryLockCond; + Mutex _tryLockMutex; }; typedef Handle<MonitorMutexTestThread> MonitorMutexTestThreadPtr; @@ -120,8 +120,8 @@ MonitorMutexTest::run() t = new MonitorMutexTestThread(monitor); control = t->start(); - // TEST: Wait until the trylock has been tested. - t->waitTrylock(); + // TEST: Wait until the tryLock has been tested. + t->waitTryLock(); } // diff --git a/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp b/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp index 7c64106a215..a437a568ba5 100644 --- a/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp +++ b/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp @@ -26,7 +26,7 @@ public: MonitorRecMutexTestThread(Monitor<RecMutex>& m) : _monitor(m), - _trylock(false) + _tryLock(false) { } @@ -37,33 +37,33 @@ public: test(!tlock.acquired()); { - Mutex::Lock lock(_trylockMutex); - _trylock = true; + Mutex::Lock lock(_tryLockMutex); + _tryLock = true; } - _trylockCond.signal(); + _tryLockCond.signal(); Monitor<RecMutex>::Lock lock(_monitor); } void - waitTrylock() + waitTryLock() { - Mutex::Lock lock(_trylockMutex); - while(!_trylock) + Mutex::Lock lock(_tryLockMutex); + while(!_tryLock) { - _trylockCond.wait(lock); + _tryLockCond.wait(lock); } } private: Monitor<RecMutex>& _monitor; - bool _trylock; + bool _tryLock; // // Use native Condition variable here, not Monitor. // - Cond _trylockCond; - Mutex _trylockMutex; + Cond _tryLockCond; + Mutex _tryLockMutex; }; typedef Handle<MonitorRecMutexTestThread> MonitorRecMutexTestThreadPtr; @@ -127,8 +127,8 @@ MonitorRecMutexTest::run() t = new MonitorRecMutexTestThread(monitor); control = t->start(); - // TEST: Wait until the trylock has been tested. - t->waitTrylock(); + // TEST: Wait until the tryLock has been tested. + t->waitTryLock(); } // diff --git a/cpp/test/IceUtil/thread/MutexTest.cpp b/cpp/test/IceUtil/thread/MutexTest.cpp index 1b463d21c8e..fa3d1ecd36c 100644 --- a/cpp/test/IceUtil/thread/MutexTest.cpp +++ b/cpp/test/IceUtil/thread/MutexTest.cpp @@ -28,7 +28,7 @@ public: MutexTestThread(Mutex& m) : _mutex(m), - _trylock(false) + _tryLock(false) { } @@ -38,33 +38,33 @@ public: test(!tlock.acquired()); { - Mutex::Lock lock(_trylockMutex); - _trylock = true; + Mutex::Lock lock(_tryLockMutex); + _tryLock = true; } - _trylockCond.signal(); + _tryLockCond.signal(); Mutex::Lock lock(_mutex); } void - waitTrylock() + waitTryLock() { - Mutex::Lock lock(_trylockMutex); - while(!_trylock) + Mutex::Lock lock(_tryLockMutex); + while(!_tryLock) { - _trylockCond.wait(lock); + _tryLockCond.wait(lock); } } private: Mutex& _mutex; - bool _trylock; + bool _tryLock; // // Use native Condition variable here, not Monitor. // - Cond _trylockCond; - Mutex _trylockMutex; + Cond _tryLockCond; + Mutex _tryLockMutex; }; typedef Handle<MutexTestThread> MutexTestThreadPtr; @@ -149,8 +149,8 @@ MutexTest::run() t = new MutexTestThread(mutex); control = t->start(); - // TEST: Wait until the trylock has been tested. - t->waitTrylock(); + // TEST: Wait until the tryLock has been tested. + t->waitTryLock(); } // diff --git a/cpp/test/IceUtil/thread/RWRecMutexTest.cpp b/cpp/test/IceUtil/thread/RWRecMutexTest.cpp index 9376c3313fc..48b1edb23a2 100644 --- a/cpp/test/IceUtil/thread/RWRecMutexTest.cpp +++ b/cpp/test/IceUtil/thread/RWRecMutexTest.cpp @@ -28,30 +28,30 @@ public: RWRecMutexTestThread(RWRecMutex& m) : _mutex(m), - _trylock(false) + _tryLock(false) { } void - waitTrylock() + waitTryLock() { - Mutex::Lock lock(_trylockMutex); - while(!_trylock) + Mutex::Lock lock(_tryLockMutex); + while(!_tryLock) { - _trylockCond.wait(lock); + _tryLockCond.wait(lock); } } protected: RWRecMutex& _mutex; - bool _trylock; + bool _tryLock; // // Use native Condition variable here, not Monitor. // - Cond _trylockCond; - Mutex _trylockMutex; + Cond _tryLockCond; + Mutex _tryLockMutex; }; class RWRecMutexReadTestThread : public RWRecMutexTestThread @@ -70,10 +70,10 @@ public: test(tlock.acquired()); { - Mutex::Lock lock(_trylockMutex); - _trylock = true; + Mutex::Lock lock(_tryLockMutex); + _tryLock = true; } - _trylockCond.signal(); + _tryLockCond.signal(); RWRecMutex::RLock lock(_mutex); } @@ -96,10 +96,10 @@ public: test(!tlock.acquired()); { - Mutex::Lock lock(_trylockMutex); - _trylock = true; + Mutex::Lock lock(_tryLockMutex); + _tryLock = true; } - _trylockCond.signal(); + _tryLockCond.signal(); RWRecMutex::RLock lock(_mutex); } @@ -255,10 +255,10 @@ public: test(!tlock.acquired()); { - Mutex::Lock lock(_trylockMutex); - _trylock = true; + Mutex::Lock lock(_tryLockMutex); + _tryLock = true; } - _trylockCond.signal(); + _tryLockCond.signal(); RWRecMutex::WLock lock(_mutex); } @@ -398,8 +398,8 @@ RWRecMutexTest::run() t = new RWRecMutexReadTestThread(mutex); control = t->start(); - // TEST: Wait until the trylock has been tested. - t->waitTrylock(); + // TEST: Wait until the tryLock has been tested. + t->waitTryLock(); } // @@ -416,8 +416,8 @@ RWRecMutexTest::run() t = new RWRecMutexWriteTestThread(mutex); control = t->start(); - // TEST: Wait until the trylock has been tested. - t->waitTrylock(); + // TEST: Wait until the tryLock has been tested. + t->waitTryLock(); } // @@ -434,9 +434,9 @@ RWRecMutexTest::run() t = new RWRecMutexWriteTestThread(mutex); control = t->start(); - // TEST: Wait until the trylock has been tested. The thread is + // TEST: Wait until the tryLock has been tested. The thread is // now waiting on a write lock. - t->waitTrylock(); + t->waitTryLock(); // It's necessary for a small sleep here to ensure that the // thread is actually waiting on a write lock. @@ -465,9 +465,9 @@ RWRecMutexTest::run() t = new RWRecMutexReadTestThread2(mutex); control = t->start(); - // TEST: Wait until the trylock has been tested. The thread is + // TEST: Wait until the tryLock has been tested. The thread is // now waiting on a read lock. - t->waitTrylock(); + t->waitTryLock(); // It's necessary for a small sleep here to ensure that the // thread is actually waiting on a read lock. diff --git a/cpp/test/IceUtil/thread/RecMutexTest.cpp b/cpp/test/IceUtil/thread/RecMutexTest.cpp index da5fab6c03c..44673fab719 100644 --- a/cpp/test/IceUtil/thread/RecMutexTest.cpp +++ b/cpp/test/IceUtil/thread/RecMutexTest.cpp @@ -28,7 +28,7 @@ public: RecMutexTestThread(RecMutex& m) : _mutex(m), - _trylock(false) + _tryLock(false) { } @@ -39,33 +39,33 @@ public: test(!tlock.acquired()); { - Mutex::Lock lock(_trylockMutex); - _trylock = true; + Mutex::Lock lock(_tryLockMutex); + _tryLock = true; } - _trylockCond.signal(); + _tryLockCond.signal(); RecMutex::Lock lock(_mutex); } void - waitTrylock() + waitTryLock() { - Mutex::Lock lock(_trylockMutex); - while(!_trylock) + Mutex::Lock lock(_tryLockMutex); + while(!_tryLock) { - _trylockCond.wait(lock); + _tryLockCond.wait(lock); } } private: RecMutex& _mutex; - bool _trylock; + bool _tryLock; // // Use native Condition variable here, not Monitor. // - Cond _trylockCond; - Mutex _trylockMutex; + Cond _tryLockCond; + Mutex _tryLockMutex; }; typedef Handle<RecMutexTestThread> RecMutexTestThreadPtr; @@ -96,8 +96,8 @@ RecMutexTest::run() t = new RecMutexTestThread(mutex); control = t->start(); - // TEST: Wait until the trylock has been tested. - t->waitTrylock(); + // TEST: Wait until the tryLock has been tested. + t->waitTryLock(); } |