Sandboxie/SandboxiePlus/MiscHelpers/Common/MT/ThreadLock.h

29 lines
676 B
C
Raw Normal View History

2022-11-12 09:45:35 +00:00
#pragma once
#include "../../mischelpers_global.h"
#include <QMutex>
#include <QWaitCondition>
/**********************************************************************************************
* CThreadLock
2022-12-23 22:11:00 +00:00
* This class allows to wait for events from a different thread.
* When Lock returns successfully, it is guaranteed that the other thread has issued a release.
* This works regardless of the real order in which Lock and Release were called.
2022-11-12 09:45:35 +00:00
*/
class MISCHELPERS_EXPORT CThreadLock
{
public:
CThreadLock();
void Reset();
bool Lock(unsigned long time = ULONG_MAX);
void Release();
protected:
QMutex m_Mutex;
QWaitCondition m_Wait;
bool m_Released;
};