CSingleLock lock(m_frameMutex);
//wait until event is set, but modify remaining time
- NotFrameCount nfc(this);
- TightConditionVariable<NotFrameCount&> cv(m_frameCond, nfc);
+ TightConditionVariable<InversePredicate<int&> > cv(m_frameCond, InversePredicate<int&>(m_frameCount));
cv.wait(lock,timeout);
done = m_frameCount == 0;
std::map<std::string, std::map<int, float> > m_lastAxisMap;
#endif
- class NotFrameCount
- {
- CApplication* ths;
- public:
- inline NotFrameCount(CApplication* o) : ths(o) {}
- inline bool operator!() { return !(ths->m_frameCount); }
- };
-
- friend class NotFrameCount;
};
extern CApplication g_application;
inline NonCopyable() {}
};
+ /**
+ * This will create a new predicate from an old predicate P with
+ * inverse truth value. This predicate is safe to use in a
+ * TightConditionVariable<P>
+ */
+ template <class P> class InversePredicate
+ {
+ P predicate;
+
+ public:
+ inline InversePredicate(P predicate_) : predicate(predicate_) {}
+ inline InversePredicate(const InversePredicate<P>& other) : predicate(other.predicate) {}
+ inline InversePredicate<P>& operator=(InversePredicate<P>& other) { predicate = other.predicate; }
+
+ inline bool operator!() const { return !(!predicate); }
+ };
+
}
#include "threads/Condition.h"
#include "threads/SingleLock.h"
+#include "threads/Helpers.h"
/**
* A CSharedSection is a mutex that satisfies the Shared Lockable concept (see Lockables.h).
{
CCriticalSection sec;
XbmcThreads::ConditionVariable actualCv;
- XbmcThreads::TightConditionVariable<bool&> cond;
+ XbmcThreads::TightConditionVariable<XbmcThreads::InversePredicate<unsigned int&> > cond;
unsigned int sharedCount;
- bool noShared;
public:
- inline CSharedSection() : cond(actualCv,noShared), sharedCount(0), noShared(true) {}
+ inline CSharedSection() : cond(actualCv,XbmcThreads::InversePredicate<unsigned int&>(sharedCount)), sharedCount(0) {}
inline void lock() { CSingleLock l(sec); if (sharedCount) cond.wait(l); sec.lock(); }
inline bool try_lock() { return (sec.try_lock() ? ((sharedCount == 0) ? true : (sec.unlock(), false)) : false); }
inline void unlock() { sec.unlock(); }
- inline void lock_shared() { CSingleLock l(sec); sharedCount++; noShared = false; }
- inline bool try_lock_shared() { return (sec.try_lock() ? sharedCount++, noShared = false, sec.unlock(), true : false); }
- inline void unlock_shared() { CSingleLock l(sec); sharedCount--; if (!sharedCount) { noShared = true; cond.notifyAll(); } }
+ inline void lock_shared() { CSingleLock l(sec); sharedCount++; }
+ inline bool try_lock_shared() { return (sec.try_lock() ? sharedCount++, sec.unlock(), true : false); }
+ inline void unlock_shared() { CSingleLock l(sec); sharedCount--; if (!sharedCount) { cond.notifyAll(); } }
};
class CSharedLock : public XbmcThreads::SharedLock<CSharedSection>