language/duchain
duchainlock.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef DUCHAINLOCK_H
00020 #define DUCHAINLOCK_H
00021
00022 #include "../languageexport.h"
00023
00024 namespace KDevelop
00025 {
00026
00027
00028
00036 #if !defined(NDEBUG) && !defined(NO_DUCHAIN_LOCK_TESTING)
00037 #define ENSURE_CHAIN_READ_LOCKED Q_ASSERT(DUChain::lock()->currentThreadHasReadLock() || DUChain::lock()->currentThreadHasWriteLock());
00038 #define ENSURE_CHAIN_WRITE_LOCKED Q_ASSERT(DUChain::lock()->currentThreadHasWriteLock());
00039 #else
00040 #define ENSURE_CHAIN_READ_LOCKED
00041 #define ENSURE_CHAIN_WRITE_LOCKED
00042 #endif
00043
00047 class KDEVPLATFORMLANGUAGE_EXPORT DUChainLock
00048 {
00049 public:
00051 DUChainLock();
00053 ~DUChainLock();
00054
00065 bool lockForRead(unsigned int timeout);
00066
00076 bool lockForRead();
00077
00081 void releaseReadLock();
00082
00086 bool currentThreadHasReadLock();
00087
00099 bool lockForWrite(uint timeout = 0);
00100
00104 void releaseWriteLock();
00105
00109 bool currentThreadHasWriteLock();
00110
00111 private:
00112 class DUChainLockPrivate* const d;
00113 };
00114
00118 class KDEVPLATFORMLANGUAGE_EXPORT DUChainReadLocker
00119 {
00120 public:
00127 DUChainReadLocker(DUChainLock* duChainLock, uint timeout = 0);
00128
00130 ~DUChainReadLocker();
00131
00133 bool lock();
00135 void unlock();
00136
00138 bool locked() const;
00139
00140 private:
00141 DUChainLock* m_lock;
00142 bool m_locked;
00143 uint m_timeout;
00144 };
00145
00149 class KDEVPLATFORMLANGUAGE_EXPORT DUChainWriteLocker
00150 {
00151 public:
00158 DUChainWriteLocker(DUChainLock* duChainLock, uint timeout = 0);
00160 ~DUChainWriteLocker();
00161
00163 bool lock();
00165 void unlock();
00166
00168 bool locked() const;
00169
00170 private:
00171 class DUChainWriteLockerPrivate* const d;
00172 };
00173
00179 #if !defined(NDEBUG) && !defined(NO_DUCHAIN_LOCK_TESTING)
00180 #define ENSURE_CAN_WRITE {if( inDUChain()) { ENSURE_CHAIN_WRITE_LOCKED }}
00181 #define ENSURE_CAN_READ {if( inDUChain()) { ENSURE_CHAIN_READ_LOCKED }}
00182 #else
00183 #define ENSURE_CAN_WRITE
00184 #define ENSURE_CAN_READ
00185 #endif
00186
00187 }
00188
00189 #endif // DUCHAINLOCK_H
00190
00191