summaryrefslogtreecommitdiff
path: root/cpp/include/IceUtil/AbstractMutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/include/IceUtil/AbstractMutex.h')
-rw-r--r--cpp/include/IceUtil/AbstractMutex.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/cpp/include/IceUtil/AbstractMutex.h b/cpp/include/IceUtil/AbstractMutex.h
new file mode 100644
index 00000000000..9d54a33c713
--- /dev/null
+++ b/cpp/include/IceUtil/AbstractMutex.h
@@ -0,0 +1,120 @@
+// **********************************************************************
+//
+// Copyright (c) 2003
+// ZeroC, Inc.
+// Billerica, MA, USA
+//
+// All Rights Reserved.
+//
+// Ice is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation.
+//
+// **********************************************************************
+
+#ifndef ICE_UTIL_ABSTRACT_MUTEX_H
+#define ICE_UTIL_ABSTRACT_MUTEX_H
+
+#include <IceUtil/Config.h>
+#include <IceUtil/Lock.h>
+
+namespace IceUtil
+{
+
+class AbstractMutex
+{
+public:
+
+ typedef LockT<AbstractMutex> Lock;
+ typedef TryLockT<AbstractMutex> TryLock;
+
+ virtual void lock() const = 0;
+ virtual void unlock() const = 0;
+ virtual bool tryLock() const = 0;
+};
+
+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()
+ {}
+};
+
+template <typename T>
+class AbstractMutexReadI : public AbstractMutex, public T
+{
+public:
+
+ typedef LockT<AbstractMutexReadI> Lock;
+ typedef TryLockT<AbstractMutexReadI> TryLock;
+
+ virtual void lock() const
+ {
+ readLock();
+ }
+
+ virtual void unlock() const
+ {
+ T::unlock();
+ }
+
+ virtual bool tryLock() const
+ {
+ return T::tryReadLock();
+ }
+
+ virtual ~AbstractMutexReadI()
+ {}
+};
+
+template <typename T>
+class AbstractMutexWriteI : public AbstractMutex, public T
+{
+public:
+
+ typedef LockT<AbstractMutexWriteI> Lock;
+ typedef TryLockT<AbstractMutexWriteI> TryLock;
+
+ virtual void lock() const
+ {
+ writeLock();
+ }
+
+ virtual void unlock() const
+ {
+ T::unlock();
+ }
+
+ virtual bool tryLock() const
+ {
+ return T::tryWriteLock();
+ }
+
+ virtual ~AbstractMutexWriteI()
+ {}
+};
+
+
+}
+
+#endif