PIMutex typedef std::mutex, patch PIMutexLocker, replace volatile by atomic
This commit is contained in:
@@ -26,51 +26,16 @@
|
||||
#include "piinit.h"
|
||||
|
||||
|
||||
//class PIP_EXPORT PIMutex
|
||||
//{
|
||||
//public:
|
||||
// //! Constructs unlocked mutex
|
||||
// explicit PIMutex();
|
||||
|
||||
// //! Destroy mutex
|
||||
// ~PIMutex();
|
||||
|
||||
|
||||
// //! \brief Lock mutex
|
||||
// //! \details If mutex is unlocked it set to locked state and returns immediate.
|
||||
// //! If mutex is already locked function blocks until mutex will be unlocked
|
||||
// void lock();
|
||||
|
||||
// //! \brief Unlock mutex
|
||||
// //! \details In any case this function returns immediate
|
||||
// void unlock();
|
||||
|
||||
// //! \brief Try to lock mutex
|
||||
// //! \details If mutex is unlocked it set to locked state and returns "true" immediate.
|
||||
// //! If mutex is already locked function returns immediate an returns "false"
|
||||
// bool tryLock();
|
||||
|
||||
// //! Returns if mutex is locked
|
||||
// bool isLocked() const;
|
||||
|
||||
//private:
|
||||
// NO_COPY_CLASS(PIMutex)
|
||||
|
||||
// void init();
|
||||
// void destroy();
|
||||
// bool inited_;
|
||||
// PRIVATE_DECLARATION
|
||||
//};
|
||||
|
||||
|
||||
class PIP_EXPORT PIMutexLocker
|
||||
{
|
||||
public:
|
||||
PIMutexLocker(PIMutex * m, bool condition = true): mutex(m), cond(condition) {if (cond) mutex->lock();}
|
||||
PIMutexLocker(PIMutex & m, bool condition = true): mutex(&m), cond(condition) {if (cond) mutex->lock();}
|
||||
~PIMutexLocker() {if (cond) mutex->unlock();}
|
||||
PIMutexLocker(PIMutex & m, bool condition = true): mutex(m), cond(condition) {if (cond) mutex.lock();}
|
||||
~PIMutexLocker() {if (cond) mutex.unlock();}
|
||||
|
||||
PIMutexLocker(const PIMutexLocker&) = delete;
|
||||
PIMutexLocker& operator=(const PIMutexLocker&) = delete;
|
||||
private:
|
||||
PIMutex * mutex;
|
||||
PIMutex & mutex;
|
||||
std::atomic_bool cond;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user