|
|
|
Copyright © 2003-2010 ZeroC, Inc. |
F.2 AbstractMutex
AbstractMutex defines a mutex base interface used by the Freeze BackgroundSaveEvictor (see Section 39.3.9). The interface allows the evictor to synchronize with servants that are stored in a Freeze database. The class has the following definition:class AbstractMutex {
public:
typedef LockT<AbstractMutex> Lock;
typedef TryLockT<AbstractMutex> TryLock;
virtual ~AbstractMutex();
virtual void lock() const = 0;
virtual void unlock() const = 0;
virtual bool tryLock() const = 0;
};This class definition is provided in IceUtil/AbstractMutex.h. The same header file also defines a few template implementation classes that specialize AbstractMutex:This template class implements AbstractMutex by forwarding all member functions to its template argument:template <typename T>
class AbstractMutexI : public AbstractMutex, public T {
public:
typedef LockT<AbstractMutexI> Lock;
typedef TryLockT<AbstractMutexI> TryLock;
virtual void lock() const {
T::lock();
}
virtual void unlock() const {
T::unlock();
}
virtual bool tryLock() const {
return T::tryLock();
}
virtual ~AbstractMutexI() {}
};This template class implements a read lock by forwarding the lock and tryLock functions to the readLock and tryReadLock functions of its template argument:template <typename T>
class AbstractMutexReadI : public AbstractMutex, public T {
public:
typedef LockT<AbstractMutexReadI> Lock;
typedef TryLockT<AbstractMutexReadI> TryLock;
virtual void lock() const {
T::readLock();
}
virtual void unlock() const {
T::unlock();
}
virtual bool tryLock() const {
return T::tryReadLock();
}
virtual ~AbstractMutexReadI() {}
};This template class implements a write lock by forwarding the lock and tryLock functions to the writeLock and tryWriteLock functions of its template argument:template <typename T>
class AbstractMutexWriteI : public AbstractMutex, public T {
public:
typedef LockT<AbstractMutexWriteI> Lock;
typedef TryLockT<AbstractMutexWriteI> TryLock;
virtual void lock() const {
T::writeLock();
}
virtual void unlock() const {
T::unlock();
}
virtual bool tryLock() const {
return T::tryWriteLock();
}
virtual ~AbstractMutexWriteI() {}
};Apart from use with Freeze servants, these templates are also useful if, for example, you want to implement your own evictor.
|
|