diff options
author | Jose <jose@zeroc.com> | 2009-12-16 16:29:39 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2009-12-16 16:29:39 +0100 |
commit | 8b0f54cbb73b47b5a34b555d539f44fbbb88bffa (patch) | |
tree | f3b33d3174be7d4d47bbb0dc3fb9b8eaea51f5ac /cpp/include | |
parent | 4479 - IcePHP StaticMutex (diff) | |
download | ice-8b0f54cbb73b47b5a34b555d539f44fbbb88bffa.tar.bz2 ice-8b0f54cbb73b47b5a34b555d539f44fbbb88bffa.tar.xz ice-8b0f54cbb73b47b5a34b555d539f44fbbb88bffa.zip |
4480 - add ICE_DEPRECATED_API to StaticMutex & RWRecMutex
Diffstat (limited to 'cpp/include')
-rw-r--r-- | cpp/include/Ice/FactoryTable.h | 1 | ||||
-rw-r--r-- | cpp/include/IceUtil/RWRecMutex.h | 83 | ||||
-rw-r--r-- | cpp/include/IceUtil/StaticMutex.h | 149 |
3 files changed, 51 insertions, 182 deletions
diff --git a/cpp/include/Ice/FactoryTable.h b/cpp/include/Ice/FactoryTable.h index 07c5c3d1bbc..9453e4cd8dd 100644 --- a/cpp/include/Ice/FactoryTable.h +++ b/cpp/include/Ice/FactoryTable.h @@ -10,7 +10,6 @@ #ifndef ICE_FACTORYTABLE_H #define ICE_FACTORYTABLE_H -#include <IceUtil/StaticMutex.h> #include <IceUtil/Mutex.h> #include <Ice/UserExceptionFactory.h> #include <Ice/ObjectFactoryF.h> diff --git a/cpp/include/IceUtil/RWRecMutex.h b/cpp/include/IceUtil/RWRecMutex.h index b2433b62b5d..0abe571180c 100644 --- a/cpp/include/IceUtil/RWRecMutex.h +++ b/cpp/include/IceUtil/RWRecMutex.h @@ -16,15 +16,19 @@ namespace IceUtil { + +// +// All classes defined in this file are now deprecated. +// class ICE_UTIL_API DeadlockException : public Exception { public: - DeadlockException(const char*, int); - virtual std::string ice_name() const; - virtual Exception* ice_clone() const; - virtual void ice_throw() const; + ICE_DEPRECATED_API DeadlockException(const char*, int); + ICE_DEPRECATED_API virtual std::string ice_name() const; + ICE_DEPRECATED_API virtual Exception* ice_clone() const; + ICE_DEPRECATED_API virtual void ice_throw() const; private: @@ -36,14 +40,14 @@ class RLockT { public: - RLockT(const T& mutex) : + ICE_DEPRECATED_API RLockT(const T& mutex) : _mutex(mutex) { _mutex.readLock(); _acquired = true; } - ~RLockT() + ICE_DEPRECATED_API ~RLockT() { if (_acquired) { @@ -51,7 +55,7 @@ public: } } - void acquire() const + ICE_DEPRECATED_API void acquire() const { if (_acquired) { @@ -61,7 +65,7 @@ public: _acquired = true; } - bool tryAcquire() const + ICE_DEPRECATED_API bool tryAcquire() const { if (_acquired) { @@ -71,7 +75,7 @@ public: return _acquired; } - bool timedAcquire(const Time& timeout) const + ICE_DEPRECATED_API bool timedAcquire(const Time& timeout) const { if (_acquired) { @@ -79,11 +83,9 @@ public: } _acquired = _mutex.timedReadLock(timeout); return _acquired; - } + } - - - void release() const + ICE_DEPRECATED_API void release() const { if (!_acquired) { @@ -93,24 +95,24 @@ public: _acquired = false; } - bool acquired() const + ICE_DEPRECATED_API bool acquired() const { return _acquired; } - void + ICE_DEPRECATED_API void upgrade() const { _mutex.upgrade(); } - bool + ICE_DEPRECATED_API bool timedUpgrade(const Time& timeout) const { return _mutex.timedUpgrade(timeout); } - void + ICE_DEPRECATED_API void downgrade() const { _mutex.downgrade(); @@ -150,12 +152,12 @@ class TryRLockT : public RLockT<T> { public: - TryRLockT(const T& mutex) : + ICE_DEPRECATED_API TryRLockT(const T& mutex) : RLockT<T>(mutex, true) { } - TryRLockT(const T& mutex, const Time& timeout) : + ICE_DEPRECATED_API TryRLockT(const T& mutex, const Time& timeout) : RLockT<T>(mutex, timeout) { } @@ -166,14 +168,14 @@ class WLockT { public: - WLockT(const T& mutex) : + ICE_DEPRECATED_API WLockT(const T& mutex) : _mutex(mutex) { _mutex.writeLock(); _acquired = true; } - ~WLockT() + ICE_DEPRECATED_API ~WLockT() { if(_acquired) { @@ -181,7 +183,7 @@ public: } } - void acquire() const + ICE_DEPRECATED_API void acquire() const { if (_acquired) { @@ -191,7 +193,7 @@ public: _acquired = true; } - bool tryAcquire() const + ICE_DEPRECATED_API bool tryAcquire() const { if (_acquired) { @@ -201,7 +203,7 @@ public: return _acquired; } - bool timedAcquire(const Time& timeout) const + ICE_DEPRECATED_API bool timedAcquire(const Time& timeout) const { if (_acquired) { @@ -211,7 +213,7 @@ public: return _acquired; } - void release() const + ICE_DEPRECATED_API void release() const { if (!_acquired) { @@ -221,7 +223,7 @@ public: _acquired = false; } - bool acquired() const + ICE_DEPRECATED_API bool acquired() const { return _acquired; } @@ -258,12 +260,12 @@ class TryWLockT : public WLockT<T> { public: - TryWLockT(const T& mutex) : + ICE_DEPRECATED_API TryWLockT(const T& mutex) : WLockT<T>(mutex, true) { } - TryWLockT(const T& mutex, const Time& timeout) : + ICE_DEPRECATED_API TryWLockT(const T& mutex, const Time& timeout) : WLockT<T>(mutex, timeout) { } @@ -279,6 +281,7 @@ public: // upgrade() or timedUpgrade() while holding a read lock promotes // the reader to a writer lock. // + class ICE_UTIL_API RWRecMutex { public: @@ -291,8 +294,8 @@ public: typedef WLockT<RWRecMutex> WLock; typedef TryWLockT<RWRecMutex> TryWLock; - RWRecMutex(); - ~RWRecMutex(); + ICE_DEPRECATED_API RWRecMutex(); + ICE_DEPRECATED_API ~RWRecMutex(); // // Note that readLock/writeLock & unlock in general should not be @@ -302,55 +305,55 @@ public: // // Acquire a read lock. // - void readLock() const; + ICE_DEPRECATED_API void readLock() const; // // Try to acquire a read lock. // - bool tryReadLock() const; + ICE_DEPRECATED_API bool tryReadLock() const; // // Try to acquire a read lock for upto the given timeout. // - bool timedReadLock(const Time&) const; + ICE_DEPRECATED_API bool timedReadLock(const Time&) const; // // Acquire a write lock. // - void writeLock() const; + ICE_DEPRECATED_API void writeLock() const; // // Acquire a write lock. // - bool tryWriteLock() const; + ICE_DEPRECATED_API bool tryWriteLock() const; // // Acquire a write lock for up to the given timeout. // - bool timedWriteLock(const Time&) const; + ICE_DEPRECATED_API bool timedWriteLock(const Time&) const; // // Unlock the reader/writer lock. // - void unlock() const; + ICE_DEPRECATED_API void unlock() const; // // Upgrade the read lock to a writer lock. Note that this method // can only be called if the reader lock is not held recursively. // - void upgrade() const; + ICE_DEPRECATED_API void upgrade() const; // // Upgrade the read lock to a writer lock for up to the given // timeout Note that this method can only be called if the reader // lock is not held recursively. // - bool timedUpgrade(const Time&) const; + ICE_DEPRECATED_API bool timedUpgrade(const Time&) const; // // Downgrade a write lock to a read lock. // - void downgrade() const; + ICE_DEPRECATED_API void downgrade() const; private: diff --git a/cpp/include/IceUtil/StaticMutex.h b/cpp/include/IceUtil/StaticMutex.h index d7e4d3c0d72..938d4801121 100644 --- a/cpp/include/IceUtil/StaticMutex.h +++ b/cpp/include/IceUtil/StaticMutex.h @@ -39,7 +39,7 @@ class Cond; // // -class StaticMutex +class ICE_UTIL_API StaticMutex { public: @@ -54,20 +54,20 @@ public: // directly. Instead use Lock & TryLock. // - void lock() const; + ICE_DEPRECATED_API void lock() const; // // Returns true if the lock was acquired, and false otherwise. // - bool tryLock() const; + ICE_DEPRECATED_API bool tryLock() const; - void unlock() const; + ICE_DEPRECATED_API void unlock() const; #ifdef _WIN32 - mutable CRITICAL_SECTION* _mutex; + ICE_DEPRECATED_API mutable CRITICAL_SECTION* _mutex; #else - mutable pthread_mutex_t _mutex; + ICE_DEPRECATED_API mutable pthread_mutex_t _mutex; #endif @@ -98,8 +98,8 @@ private: void lock(LockState&) const; #ifdef _WIN32 - inline bool initialized() const; - ICE_UTIL_API void initialize() const; + bool initialized() const; + void initialize() const; #endif #ifndef _MSC_VER @@ -114,139 +114,6 @@ private: # define ICE_STATIC_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } #endif -// -// For performance reasons the following functions are inlined. -// - -#ifdef _WIN32 - -inline bool -StaticMutex::initialized() const -{ - // - // Read mutex and then inserts a memory barrier to ensure we can't - // see tmp != 0 before we see the initialized object - // - void* tmp = _mutex; - return InterlockedCompareExchangePointer(reinterpret_cast<void**>(&tmp), 0, 0) != 0; -} - -inline void -StaticMutex::lock() const -{ - if(!initialized()) - { - initialize(); - } - EnterCriticalSection(_mutex); - assert(_mutex->RecursionCount == 1); -} - -inline bool -StaticMutex::tryLock() const -{ - if(!initialized()) - { - initialize(); - } - if(!TryEnterCriticalSection(_mutex)) - { - return false; - } - if(_mutex->RecursionCount > 1) - { - LeaveCriticalSection(_mutex); - throw ThreadLockedException(__FILE__, __LINE__); - } - return true; -} - -inline void -StaticMutex::unlock() const -{ - assert(_mutex != 0); - assert(_mutex->RecursionCount == 1); - LeaveCriticalSection(_mutex); -} - -inline void -StaticMutex::unlock(LockState&) const -{ - assert(_mutex != 0); - assert(_mutex->RecursionCount == 1); - LeaveCriticalSection(_mutex); -} - -inline void -StaticMutex::lock(LockState&) const -{ - if(!initialized()) - { - initialize(); - } - EnterCriticalSection(_mutex); -} - -#else - -inline void -StaticMutex::lock() const -{ - int rc = pthread_mutex_lock(&_mutex); - if(rc != 0) - { - if(rc == EDEADLK) - { - throw ThreadLockedException(__FILE__, __LINE__); - } - else - { - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } - } -} - -inline bool -StaticMutex::tryLock() const -{ - int rc = pthread_mutex_trylock(&_mutex); - if(rc != 0 && rc != EBUSY) - { - if(rc == EDEADLK) - { - throw ThreadLockedException(__FILE__, __LINE__); - } - else - { - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } - } - return (rc == 0); -} - -inline void -StaticMutex::unlock() const -{ - int rc = pthread_mutex_unlock(&_mutex); - if(rc != 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } -} - -inline void -StaticMutex::unlock(LockState& state) const -{ - state.mutex = &_mutex; -} - -inline void -StaticMutex::lock(LockState&) const -{ -} - -#endif - } // End namespace IceUtil #endif |