/*
* This file is part of the libCEC(R) library.
*
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
* libCEC(R) is an original work, containing original code.
*
* libCEC(R) is a trademark of Pulse-Eight Limited.
* http://www.pulse-eight.net/
*/
+#include "../os.h"
+
+#if defined(__WINDOWS__)
+#include "../windows/os-threads.h"
+#else
+#include "../posix/os-threads.h"
+#endif
+
namespace PLATFORM
{
class PreventCopy
inline void Unlock(void)
{
- --m_iLockCount;
- MutexUnlock(m_mutex);
+ if (Lock())
+ {
+ if (m_iLockCount >= 2)
+ {
+ --m_iLockCount;
+ MutexUnlock(m_mutex);
+ }
+
+ --m_iLockCount;
+ MutexUnlock(m_mutex);
+ }
}
inline bool Clear(void)
}
private:
- mutex_t m_mutex;
- unsigned int m_iLockCount;
+ mutex_t m_mutex;
+ volatile unsigned int m_iLockCount;
};
class CLockObject : public PreventCopy