summaryrefslogtreecommitdiff
path: root/cpp/include
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2001-12-31 14:27:22 +0000
committerMatthew Newhook <matthew@zeroc.com>2001-12-31 14:27:22 +0000
commitb51bb7c6bd2f50932219e96573939cef1f5c018c (patch)
tree45ca849effd41e325369ad2bf288476efba8bb52 /cpp/include
parentinitial server support; align with stable_31 (diff)
downloadice-b51bb7c6bd2f50932219e96573939cef1f5c018c.tar.bz2
ice-b51bb7c6bd2f50932219e96573939cef1f5c018c.tar.xz
ice-b51bb7c6bd2f50932219e96573939cef1f5c018c.zip
Remove ConstLock, and friends.
Diffstat (limited to 'cpp/include')
-rw-r--r--cpp/include/IceUtil/Cond.h50
-rw-r--r--cpp/include/IceUtil/Lock.h58
-rw-r--r--cpp/include/IceUtil/Monitor.h31
-rw-r--r--cpp/include/IceUtil/Mutex.h37
-rw-r--r--cpp/include/IceUtil/RWRecMutex.h125
-rw-r--r--cpp/include/IceUtil/RecMutex.h19
-rw-r--r--cpp/include/IceUtil/Thread.h2
7 files changed, 86 insertions, 236 deletions
diff --git a/cpp/include/IceUtil/Cond.h b/cpp/include/IceUtil/Cond.h
index a7202335784..b3274c77464 100644
--- a/cpp/include/IceUtil/Cond.h
+++ b/cpp/include/IceUtil/Cond.h
@@ -46,12 +46,12 @@ public:
Semaphore(long = 0);
~Semaphore();
- bool wait(long = -1);
- void post(int = 1);
+ bool wait(long = -1) const;
+ void post(int = 1) const;
private:
- HANDLE _sem;
+ mutable HANDLE _sem;
};
#else
@@ -79,9 +79,9 @@ public:
void signal();
//
- // pthread_cond_broadcast restarts all the threads that are
- // waiting on the condition variable cond. Nothing happens if no
- // threads are waiting on cond.
+ // broadcast restarts all the threads that are waiting on the
+ // condition variable cond. Nothing happens if no threads are
+ // waiting on cond.
//
void broadcast();
@@ -96,7 +96,7 @@ public:
// the mutex is reaquired.
//
template <typename Lock> inline void
- wait(Lock& lock)
+ wait(const Lock& lock) const
{
waitImpl(lock._mutex);
}
@@ -109,7 +109,7 @@ public:
// timeout.
//
template <typename Lock> inline bool
- timedwait(Lock& lock, long msec)
+ timedwait(const Lock& lock, long msec) const
{
timedwaitImpl(lock._mutex, msec);
}
@@ -131,7 +131,7 @@ private:
//
/*
template <typename M> void
- waitImpl(M& mutex)
+ waitImpl(const M& mutex) const
{
preWait();
@@ -152,7 +152,7 @@ private:
}
}
template <typename M> bool
- timedwaitImpl(M& mutex, long msec)
+ timedwaitImpl(const M& mutex, long msec) const
{
preWait();
@@ -176,7 +176,7 @@ private:
*/
void
- waitImpl(RecMutex& mutex)
+ waitImpl(const RecMutex& mutex) const
{
preWait();
@@ -196,7 +196,7 @@ private:
}
void
- waitImpl(Mutex& mutex)
+ waitImpl(const Mutex& mutex) const
{
preWait();
@@ -216,7 +216,7 @@ private:
}
bool
- timedwaitImpl(RecMutex& mutex, long msec)
+ timedwaitImpl(const RecMutex& mutex, long msec) const
{
preWait();
@@ -237,7 +237,7 @@ private:
}
bool
- timedwaitImpl(Mutex& mutex, long msec)
+ timedwaitImpl(const Mutex& mutex, long msec) const
{
preWait();
@@ -259,32 +259,32 @@ private:
#else
- template <typename M> void waitImpl(M&);
- template <typename M> bool timedwaitImpl(M&, long);
+ template <typename M> void waitImpl(const M&) const;
+ template <typename M> bool timedwaitImpl(const M&, long) const;
#endif
#ifdef WIN32
void wake(bool);
- void preWait();
- void postWait(bool);
- bool dowait(long);
+ void preWait() const;
+ void postWait(bool) const;
+ bool dowait(long) const;
Mutex _internal;
Semaphore _gate;
Semaphore _queue;
- long _blocked;
- long _unblocked;
- long _toUnblock;
+ mutable long _blocked;
+ mutable long _unblocked;
+ mutable long _toUnblock;
#else
- pthread_cond_t _cond;
+ mutable pthread_cond_t _cond;
#endif
};
#ifndef WIN32
template <typename M> inline void
-Cond::waitImpl(M& mutex)
+Cond::waitImpl(const M& mutex) const
{
typedef typename M::LockState LockState;
@@ -300,7 +300,7 @@ Cond::waitImpl(M& mutex)
}
template <typename M> inline bool
-Cond::timedwaitImpl(M& mutex, long msec)
+Cond::timedwaitImpl(const M& mutex, long msec) const
{
typedef typename M::LockState LockState;
diff --git a/cpp/include/IceUtil/Lock.h b/cpp/include/IceUtil/Lock.h
index 4fb921c8a66..d5b9d2ca14b 100644
--- a/cpp/include/IceUtil/Lock.h
+++ b/cpp/include/IceUtil/Lock.h
@@ -26,7 +26,7 @@ class Lock
{
public:
- Lock(T& mutex) :
+ Lock(const T& mutex) :
_mutex(mutex)
{
_mutex.lock();
@@ -39,7 +39,7 @@ public:
private:
- T& _mutex;
+ const T& _mutex;
friend class Cond;
};
@@ -49,7 +49,7 @@ class TryLock
{
public:
- TryLock(T& mutex) :
+ TryLock(const T& mutex) :
_mutex(mutex)
{
_mutex.trylock();
@@ -62,57 +62,7 @@ public:
private:
- T& _mutex;
-
- friend class Cond;
-};
-
-//
-// This is for use when a class derives from Mutex, Monitor or
-// RecMutex. Otherwise declare the concurrency primitive mutable.
-//
-template <typename T>
-class ConstLock
-{
-public:
-
- ConstLock(const T& mutex) :
- _mutex(const_cast<T&>(mutex))
- {
- _mutex.lock();
- }
-
- ~ConstLock()
- {
- _mutex.unlock();
- }
-
-private:
-
- T& _mutex;
-
- friend class Cond;
-};
-
-template <typename T>
-class ConstTryLock
-{
-public:
-
- ConstTryLock(const T& mutex) :
- _mutex(const_cast<T>(mutex))
- {
- _mutex.trylock();
- }
-
- ~ConstTryLock()
- {
- _mutex.unlock();
- }
-
-private:
-
- T& _mutex;
+ const T& _mutex;
friend class Cond;
};
diff --git a/cpp/include/IceUtil/Monitor.h b/cpp/include/IceUtil/Monitor.h
index 77af7f53822..36b14f9bb58 100644
--- a/cpp/include/IceUtil/Monitor.h
+++ b/cpp/include/IceUtil/Monitor.h
@@ -31,9 +31,6 @@ public:
typedef Lock<Monitor<T> > Lock;
typedef TryLock<Monitor<T> > TryLock;
- typedef ConstLock<Monitor<T> > ConstLock;
- typedef ConstTryLock<Monitor<T> > ConstTryLock;
-
Monitor();
~Monitor();
@@ -41,12 +38,12 @@ public:
// Note that lock/trylock & unlock in general should not be used
// directly. Instead use Lock & TryLock.
//
- void lock();
- void unlock();
- void trylock();
+ void lock() const;
+ void unlock() const;
+ void trylock() const;
- void wait();
- bool timedwait(long);
+ void wait() const;
+ bool timedwait(long) const;
void notify();
void notifyAll();
@@ -56,11 +53,11 @@ private:
Monitor(const Monitor&);
void operator=(const Monitor&);
- void notifyImpl(int);
+ void notifyImpl(int) const;
- Cond _cond;
+ mutable Cond _cond;
T _mutex;
- int _nnotify;
+ mutable int _nnotify;
};
} // End namespace IceUtil
@@ -88,7 +85,7 @@ IceUtil::Monitor<T>::~Monitor()
}
template <class T> inline void
-IceUtil::Monitor<T>::lock()
+IceUtil::Monitor<T>::lock() const
{
if (_mutex.lock())
{
@@ -101,7 +98,7 @@ IceUtil::Monitor<T>::lock()
}
template <class T> inline void
-IceUtil::Monitor<T>::unlock()
+IceUtil::Monitor<T>::unlock() const
{
int nnotify = _nnotify;
if (_mutex.unlock())
@@ -114,7 +111,7 @@ IceUtil::Monitor<T>::unlock()
}
template <class T> inline void
-IceUtil::Monitor<T>::trylock()
+IceUtil::Monitor<T>::trylock() const
{
if (_mutex.trylock())
{
@@ -127,7 +124,7 @@ IceUtil::Monitor<T>::trylock()
}
template <class T> inline void
-IceUtil::Monitor<T>::wait()
+IceUtil::Monitor<T>::wait() const
{
//
// Perform any pending notifies
@@ -153,7 +150,7 @@ IceUtil::Monitor<T>::wait()
}
template <class T> inline bool
-IceUtil::Monitor<T>::timedwait(long msec)
+IceUtil::Monitor<T>::timedwait(long msec) const
{
//
// Perform any pending notifies.
@@ -206,7 +203,7 @@ IceUtil::Monitor<T>::notifyAll()
template <class T> inline void
-IceUtil::Monitor<T>::notifyImpl(int nnotify)
+IceUtil::Monitor<T>::notifyImpl(int nnotify) const
{
//
// Zero indicates no notifies.
diff --git a/cpp/include/IceUtil/Mutex.h b/cpp/include/IceUtil/Mutex.h
index 5b4ffdaf3ee..0c43398b279 100644
--- a/cpp/include/IceUtil/Mutex.h
+++ b/cpp/include/IceUtil/Mutex.h
@@ -43,9 +43,6 @@ public:
typedef Lock<Mutex> Lock;
typedef TryLock<Mutex> TryLock;
- typedef ConstLock<Mutex> ConstLock;
- typedef ConstTryLock<Mutex> ConstTryLock;
-
Mutex();
~Mutex();
@@ -64,7 +61,7 @@ public:
//
// Return true if the mutex has been locked for the first time.
//
- bool lock();
+ bool lock() const;
//
// Throw LockedException in the case that the lock call would
@@ -72,13 +69,13 @@ public:
// thread). Returns true if the mutex has been locked for the
// first time.
//
- bool trylock();
+ bool trylock() const;
//
// Returns true if the mutex has been unlocked for the last time
// (false otherwise).
//
- bool unlock();
+ bool unlock() const;
private:
@@ -101,15 +98,15 @@ private:
};
#endif
- void unlock(LockState&);
- void lock(LockState&);
+ void unlock(LockState&) const;
+ void lock(LockState&) const;
friend class Cond;
#ifdef WIN32
- CRITICAL_SECTION _mutex;
+ mutable CRITICAL_SECTION _mutex;
#else
- pthread_mutex_t _mutex;
+ mutable pthread_mutex_t _mutex;
#endif
};
@@ -127,7 +124,7 @@ Mutex::~Mutex()
}
inline bool
-Mutex::lock()
+Mutex::lock() const
{
EnterCriticalSection(&_mutex);
//
@@ -139,7 +136,7 @@ Mutex::lock()
}
inline bool
-Mutex::trylock()
+Mutex::trylock() const
{
if (!TryEnterCriticalSection(&_mutex))
{
@@ -154,7 +151,7 @@ Mutex::trylock()
}
inline bool
-Mutex::unlock()
+Mutex::unlock() const
{
assert(_mutex.RecursionCount == 1);
LeaveCriticalSection(&_mutex);
@@ -162,13 +159,13 @@ Mutex::unlock()
}
inline void
-Mutex::unlock(LockState& state)
+Mutex::unlock(LockState& state) const
{
LeaveCriticalSection(&_mutex);
}
inline void
-Mutex::lock(LockState&)
+Mutex::lock(LockState&) const
{
EnterCriticalSection(&_mutex);
}
@@ -194,7 +191,7 @@ Mutex::~Mutex()
}
inline bool
-Mutex::lock()
+Mutex::lock() const
{
int rc = pthread_mutex_lock(&_mutex);
if (rc != 0)
@@ -205,7 +202,7 @@ Mutex::lock()
}
inline bool
-Mutex::trylock()
+Mutex::trylock() const
{
int rc = pthread_mutex_trylock(&_mutex);
if (rc != 0)
@@ -220,7 +217,7 @@ Mutex::trylock()
}
inline bool
-Mutex::unlock()
+Mutex::unlock() const
{
int rc = pthread_mutex_unlock(&_mutex);
if (rc != 0)
@@ -231,13 +228,13 @@ Mutex::unlock()
}
inline void
-Mutex::unlock(LockState& state)
+Mutex::unlock(LockState& state) const
{
state.mutex = &_mutex;
}
inline void
-Mutex::lock(LockState&)
+Mutex::lock(LockState&) const
{
}
#endif
diff --git a/cpp/include/IceUtil/RWRecMutex.h b/cpp/include/IceUtil/RWRecMutex.h
index df8efe6e0bd..518eac78d58 100644
--- a/cpp/include/IceUtil/RWRecMutex.h
+++ b/cpp/include/IceUtil/RWRecMutex.h
@@ -22,7 +22,7 @@ class RLock
{
public:
- RLock(T& mutex) :
+ RLock(const T& mutex) :
_mutex(mutex)
{
_mutex.readLock();
@@ -35,28 +35,7 @@ public:
private:
- T& _mutex;
-};
-
-template <typename T>
-class ConstRLock
-{
-public:
-
- ConstRLock(const T& mutex) :
- _mutex(const_cast<T>(mutex))
- {
- _mutex.readLock();
- }
-
- ~ConstRLock()
- {
- _mutex.unlock();
- }
-
-private:
-
- T& _mutex;
+ const T& _mutex;
};
template <typename T>
@@ -64,7 +43,7 @@ class TryRLock
{
public:
- TryRLock(T& mutex) :
+ TryRLock(const T& mutex) :
_mutex(mutex)
{
_mutex.tryReadLock();
@@ -77,28 +56,7 @@ public:
private:
- T& _mutex;
-};
-
-template <typename T>
-class ConstTryRLock
-{
-public:
-
- ConstTryRLock(const T& mutex) :
- _mutex(const_cast<T>(mutex))
- {
- _mutex.tryReadLock();
- }
-
- ~ConstTryRLock()
- {
- _mutex.unlock();
- }
-
-private:
-
- T& _mutex;
+ const T& _mutex;
};
template <typename T>
@@ -106,7 +64,7 @@ class WLock
{
public:
- WLock(T& mutex) :
+ WLock(const T& mutex) :
_mutex(mutex)
{
_mutex.writeLock();
@@ -119,28 +77,7 @@ public:
private:
- T& _mutex;
-};
-
-template <typename T>
-class ConstWLock
-{
-public:
-
- ConstWLock(const T& mutex) :
- _mutex(const_cast<T>(mutex))
- {
- _mutex.writeLock();
- }
-
- ~ConstWLock()
- {
- _mutex.unlock();
- }
-
-private:
-
- T& _mutex;
+ const T& _mutex;
};
template <typename T>
@@ -148,7 +85,7 @@ class TryWLock
{
public:
- TryWLock(T& mutex) :
+ TryWLock(const T& mutex) :
_mutex(mutex)
{
_mutex.tryWriteLock();
@@ -161,29 +98,7 @@ public:
private:
- T& _mutex;
-};
-
-
-template <typename T>
-class ConstTryWLock
-{
-public:
-
- ConstTryWLock(const T& mutex) :
- _mutex(const_cast<T>(mutex))
- {
- _mutex.tryWriteLock();
- }
-
- ~ConstTryWLock()
- {
- _mutex.unlock();
- }
-
-private:
-
- T& _mutex;
+ const T& _mutex;
};
//
@@ -204,12 +119,6 @@ public:
typedef WLock<RWRecMutex> WLock;
typedef TryWLock<RWRecMutex> TryWLock;
- typedef ConstRLock<RWRecMutex> ConstRLock;
- typedef ConstTryRLock<RWRecMutex> ConstTryRLock;
- typedef ConstWLock<RWRecMutex> ConstWLock;
- typedef ConstTryWLock<RWRecMutex> ConstTryWLock;
-
-
RWRecMutex();
~RWRecMutex();
@@ -221,27 +130,27 @@ public:
//
// Acquire a read lock.
//
- void readLock();
+ void readLock() const;
//
// Try to acquire a read lock.
//
- void tryReadLock();
+ void tryReadLock() const;
//
// Acquire a write lock.
//
- void writeLock();
+ void writeLock() const;
//
// Acquire a write lock.
//
- void tryWriteLock();
+ void tryWriteLock() const;
//
// Unlock the reader/writer lock.
//
- void unlock();
+ void unlock() const;
private:
@@ -253,12 +162,12 @@ private:
// Number of readers holding the lock. -1 means a writer has the
// lock.
//
- int _count;
+ mutable int _count;
//
// Number of waiting writers.
//
- unsigned int _waitingWriters;
+ mutable unsigned int _waitingWriters;
//
// Internal mutex.
@@ -268,8 +177,8 @@ private:
//
// Two condition variables for waiting readers & writers.
//
- Cond _readers;
- Cond _writers;
+ mutable Cond _readers;
+ mutable Cond _writers;
};
} // End namespace IceUtil
diff --git a/cpp/include/IceUtil/RecMutex.h b/cpp/include/IceUtil/RecMutex.h
index 5ef5f42f342..9f0e3b51319 100644
--- a/cpp/include/IceUtil/RecMutex.h
+++ b/cpp/include/IceUtil/RecMutex.h
@@ -35,9 +35,6 @@ public:
typedef Lock<RecMutex> Lock;
typedef TryLock<RecMutex> TryLock;
- typedef ConstLock<RecMutex> ConstLock;
- typedef ConstTryLock<RecMutex> ConstTryLock;
-
RecMutex();
~RecMutex();
@@ -56,7 +53,7 @@ public:
//
// Return true if the mutex has been locked for the first time.
//
- bool lock();
+ bool lock() const;
//
// Throw LockedException in the case that the lock call would
@@ -64,13 +61,13 @@ public:
// thread). Returns true if the mutex has been locked for the
// first time.
//
- bool trylock();
+ bool trylock() const;
//
// Returns true if the mutex has been unlocked for the last time
// (false otherwise).
//
- bool unlock();
+ bool unlock() const;
private:
@@ -95,18 +92,18 @@ private:
};
#endif
- void unlock(LockState&);
- void lock(LockState&);
+ void unlock(LockState&) const;
+ void lock(LockState&) const;
friend class Cond;
#ifdef WIN32
- CRITICAL_SECTION _mutex;
+ mutable CRITICAL_SECTION _mutex;
#else
- pthread_mutex_t _mutex;
+ mutable pthread_mutex_t _mutex;
#endif
- int _count;
+ mutable int _count;
};
} // End namespace IceUtil
diff --git a/cpp/include/IceUtil/Thread.h b/cpp/include/IceUtil/Thread.h
index 4d1a9551cc5..8ff7f171a38 100644
--- a/cpp/include/IceUtil/Thread.h
+++ b/cpp/include/IceUtil/Thread.h
@@ -87,7 +87,7 @@ private:
#endif
};
-class ICE_UTIL_API Thread : public IceUtil::Shared
+class ICE_UTIL_API Thread : public virtual IceUtil::Shared
{
public: