mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-11 00:58:14 +08:00
performance fixes on win32 plus clean up of some warnings. also
improved error messages when uninstalling service.
This commit is contained in:
@@ -105,6 +105,16 @@ CThread::wait(
|
||||
return currentRep->wait(m_rep, timeout);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_PLATFORM_WIN32)
|
||||
bool
|
||||
CThread::waitForEvent(
|
||||
double timeout)
|
||||
{
|
||||
CThreadPtr currentRep(CThreadRep::getCurrentThreadRep());
|
||||
return currentRep->waitForEvent(timeout);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
CThread::testCancel()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef CTHREAD_H
|
||||
#define CTHREAD_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class IJob;
|
||||
class CThreadRep;
|
||||
|
||||
@@ -103,6 +105,13 @@ public:
|
||||
// (cancellation point)
|
||||
bool wait(double timeout = -1.0) const;
|
||||
|
||||
#if defined(CONFIG_PLATFORM_WIN32)
|
||||
// wait for a message in the queue. returns true if a message
|
||||
// is available.
|
||||
// (cancellation point)
|
||||
static bool waitForEvent(double timeout = -1.0);
|
||||
#endif
|
||||
|
||||
// get the exit result. does an implicit wait(). returns NULL
|
||||
// immediately if called by a thread on itself. returns NULL for
|
||||
// threads that were cancelled.
|
||||
|
||||
@@ -614,7 +614,45 @@ CThreadRep::wait(
|
||||
testCancel();
|
||||
|
||||
default:
|
||||
// error
|
||||
// timeout or error
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
CThreadRep::waitForEvent(
|
||||
double timeout)
|
||||
{
|
||||
// is cancellation enabled?
|
||||
const DWORD n = (isCancellable() ? 1 : 0);
|
||||
|
||||
// convert timeout
|
||||
DWORD t;
|
||||
if (timeout < 0.0) {
|
||||
t = INFINITE;
|
||||
}
|
||||
else {
|
||||
t = (DWORD)(1000.0 * timeout);
|
||||
}
|
||||
|
||||
// wait for this thread to be cancelled or for the target thread to
|
||||
// terminate.
|
||||
HANDLE handles[1];
|
||||
handles[0] = m_cancel;
|
||||
DWORD result = MsgWaitForMultipleObjects(n, handles, FALSE, t, QS_ALLINPUT);
|
||||
|
||||
// handle result
|
||||
switch (result) {
|
||||
case WAIT_OBJECT_0 + 1:
|
||||
// message is available
|
||||
return true;
|
||||
|
||||
case WAIT_OBJECT_0 + 0:
|
||||
// this thread was cancelled. does not return.
|
||||
testCancel();
|
||||
|
||||
default:
|
||||
// timeout or error
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@ public:
|
||||
// wait for thread to exit or for current thread to cancel
|
||||
bool wait(CThreadRep*, double timeout);
|
||||
|
||||
#if defined(CONFIG_PLATFORM_WIN32)
|
||||
// wait for a message on the queue
|
||||
bool waitForEvent(double timeout);
|
||||
#endif
|
||||
|
||||
// set the priority
|
||||
void setPriority(int n);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user