44 inline QuickEvent(
const bool signaled=
false) : hEvent(NULL)
46 hEvent = CreateEvent(NULL,
TRUE, (BOOL)signaled, NULL);
62 return(WAIT_OBJECT_0 == WaitForSingleObject(hEvent, 0));
66 return(WAIT_OBJECT_0 == WaitForSingleObject(hEvent, (DWORD)milliseconds));
98 static DWORD WINAPI
Thunk(LPVOID lpParameter)
122 inline QuickThread(F* proc,
void* params,
const bool auto_release=
false) : hThread(NULL)
136 state.
sigclone = &hWaitThunkCloneState;
142 hWaitThunkCloneState.
Wait();
149 if (hThread == GetCurrentThread())
151 CloseHandle(hThread);
161 WaitForSingleObject(hThread, INFINITE);
166 return(WAIT_OBJECT_0 == WaitForSingleObject(hThread, 0));
171 return(
TRUE == SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL));
176 return(
TRUE == SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL));
179 static inline void Sleep(
int milliseconds)
181 ::Sleep(milliseconds);
215 InitializeCriticalSection(&cs);
220 DeleteCriticalSection(&cs);
225 return(0 != TryEnterCriticalSection(&cs));
230 EnterCriticalSection(&cs);
235 LeaveCriticalSection(&cs);
253 m_vEvents.push_back(poEvent);
254 m_vHandles.push_back(poEvent->
hEvent);
262 std::vector<QuickEvent*>::iterator it1 = std::find(m_vEvents.begin(), m_vEvents.end(), poEvent);
263 m_vEvents.erase(it1);
264 std::vector<HANDLE>::iterator it2 = std::find(m_vHandles.begin(), m_vHandles.end(), poEvent->
hEvent);
265 m_vHandles.erase(it2);
274 DWORD ret (WAIT_FAILED);
275 const unsigned int nHandles (m_vHandles.size());
277 ret = WaitForMultipleObjects(nHandles, &m_vHandles[0],
FALSE, milliseconds);
278 if (ret - WAIT_OBJECT_0 < nHandles)
279 index = (int)(ret - WAIT_OBJECT_0);
286 return(WaitAnyUntilTimeout(INFINITE));
291 return(WaitAnyUntilTimeout(0));
298 const unsigned int nHandles (m_vHandles.size());
300 waited = (WAIT_TIMEOUT != WaitForMultipleObjects(nHandles, &m_vHandles[0],
FALSE, milliseconds));
307 return(WaitAllUntilTimeout(INFINITE));
314 poEvent = m_vEvents[index];
int WaitAnyUntilTimeout(const unsigned int milliseconds)
static DWORD WINAPI Thunk(LPVOID lpParameter)
std::vector< QuickEvent * > m_vEvents
QuickEvent(const bool signaled=false)
const bool WaitUntilTimeout(const unsigned int milliseconds)
const bool AttachEvent(QuickEvent *poEvent)
const bool WaitAllUntilTimeout(const unsigned int milliseconds)
std::vector< HANDLE > m_vHandles
QuickThread(F *proc, void *params, const bool auto_release=false)
static void Sleep(int milliseconds)
static QuickThread Myself()
const bool DetachEvent(QuickEvent *poEvent)