foobar2000 SDK  2015-08-03
Data Structures | Functions
ThreadUtils Namespace Reference

Data Structures

class  CObjectQueue
 
class  CSingleThreadWrapper
 

Functions

static t_size MultiWaitAbortable_MsgLoop (const HANDLE *ev, t_size evCount, abort_callback &abort)
 
static void ProcessPendingMessages ()
 
static void SleepAbortable_MsgLoop (abort_callback &abort, DWORD timeout)
 
static bool WaitAbortable (HANDLE ev, abort_callback &abort, DWORD timeout=INFINITE)
 
static void WaitAbortable_MsgLoop (HANDLE ev, abort_callback &abort)
 
static bool WaitAbortable_MsgLoop (HANDLE ev, abort_callback &abort, DWORD timeout)
 

Function Documentation

static t_size ThreadUtils::MultiWaitAbortable_MsgLoop ( const HANDLE ev,
t_size  evCount,
abort_callback abort 
)
static

Definition at line 53 of file ThreadUtils.h.

53  {
54  pfc::array_t<HANDLE> handles; handles.set_size(evCount + 1);
55  handles[0] = abort.get_abort_event();
56  pfc::memcpy_t(handles.get_ptr() + 1, ev, evCount);
57  for(;;) {
58  SetLastError(0);
59  const DWORD status = MsgWaitForMultipleObjects(handles.get_count(), handles.get_ptr(), FALSE, INFINITE, QS_ALLINPUT);
60  switch(status) {
61  case WAIT_TIMEOUT:
62  PFC_ASSERT(!"How did we get here?");
63  uBugCheck();
64  case WAIT_OBJECT_0:
65  throw exception_aborted();
66  case WAIT_FAILED:
67  WIN32_OP_FAIL();
68  default:
69  {
70  t_size index = (t_size)(status - (WAIT_OBJECT_0 + 1));
71  if (index == evCount) {
73  } else if (index < evCount) {
74  return index;
75  } else {
76  uBugCheck();
77  }
78  }
79  }
80  }
81  }
const t_item * get_ptr() const
Definition: array.h:213
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL()
Definition: win32_misc.cpp:52
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
t_size get_count() const
Definition: array.h:131
void memcpy_t(t_dst *p_dst, const t_src *p_src, t_size p_count)
Definition: primitives.h:611
PFC_NORETURN void SHARED_EXPORT uBugCheck()
static void ProcessPendingMessages()
Definition: ThreadUtils.h:21
static void ThreadUtils::ProcessPendingMessages ( )
static

Definition at line 21 of file ThreadUtils.h.

21  {
22  MSG msg = {};
23  while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
24  DispatchMessage(&msg);
25  }
26  }
static void ThreadUtils::SleepAbortable_MsgLoop ( abort_callback abort,
DWORD  timeout 
)
static

Definition at line 83 of file ThreadUtils.h.

83  {
84  PFC_ASSERT( timeout != INFINITE );
85  const DWORD entry = GetTickCount();
86  const HANDLE handles[1] = {abort.get_abort_event()};
87  for(;;) {
88  const DWORD done = GetTickCount() - entry;
89  if (done >= timeout) return;
90  SetLastError(0);
91  const DWORD status = MsgWaitForMultipleObjects(1, handles, FALSE, timeout - done, QS_ALLINPUT);
92  switch(status) {
93  case WAIT_TIMEOUT:
94  return;
95  case WAIT_OBJECT_0:
96  throw exception_aborted();
97  case WAIT_OBJECT_0 + 1:
99  default:
100  throw exception_win32(GetLastError());
101  }
102  }
103  }
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
static void ProcessPendingMessages()
Definition: ThreadUtils.h:21
static bool ThreadUtils::WaitAbortable ( HANDLE  ev,
abort_callback abort,
DWORD  timeout = INFINITE 
)
static

Definition at line 2 of file ThreadUtils.h.

2  {
3  const HANDLE handles[2] = {ev, abort.get_abort_event()};
4  SetLastError(0);
5  const DWORD status = WaitForMultipleObjects(2, handles, FALSE, timeout);
6  switch(status) {
7  case WAIT_TIMEOUT:
8  PFC_ASSERT( timeout != INFINITE );
9  return false;
10  case WAIT_OBJECT_0:
11  return true;
12  case WAIT_OBJECT_0 + 1:
13  throw exception_aborted();
14  case WAIT_FAILED:
15  WIN32_OP_FAIL();
16  default:
17  uBugCheck();
18  }
19  }
DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds)
Definition: pp-winapi.h:20
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL()
Definition: win32_misc.cpp:52
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
PFC_NORETURN void SHARED_EXPORT uBugCheck()
static void ThreadUtils::WaitAbortable_MsgLoop ( HANDLE  ev,
abort_callback abort 
)
static

Definition at line 29 of file ThreadUtils.h.

29  {
30  const HANDLE handles[2] = {ev, abort.get_abort_event()};
31  for(;;) {
32  SetLastError(0);
33  const DWORD status = MsgWaitForMultipleObjects(2, handles, FALSE, INFINITE, QS_ALLINPUT);
34  switch(status) {
35  case WAIT_TIMEOUT:
36  PFC_ASSERT(!"How did we get here?");
37  uBugCheck();
38  case WAIT_OBJECT_0:
39  return;
40  case WAIT_OBJECT_0 + 1:
41  throw exception_aborted();
42  case WAIT_OBJECT_0 + 2:
44  break;
45  case WAIT_FAILED:
46  WIN32_OP_FAIL();
47  default:
48  uBugCheck();
49  }
50  }
51  }
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL()
Definition: win32_misc.cpp:52
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
PFC_NORETURN void SHARED_EXPORT uBugCheck()
static void ProcessPendingMessages()
Definition: ThreadUtils.h:21
static bool ThreadUtils::WaitAbortable_MsgLoop ( HANDLE  ev,
abort_callback abort,
DWORD  timeout 
)
static

Definition at line 105 of file ThreadUtils.h.

105  {
106  PFC_ASSERT( timeout != INFINITE );
107  const DWORD entry = GetTickCount();
108  const HANDLE handles[2] = {ev, abort.get_abort_event()};
109  for(;;) {
110  const DWORD done = GetTickCount() - entry;
111  if (done >= timeout) return false;
112  SetLastError(0);
113  const DWORD status = MsgWaitForMultipleObjects(2, handles, FALSE, timeout - done, QS_ALLINPUT);
114  switch(status) {
115  case WAIT_TIMEOUT:
116  return false;
117  case WAIT_OBJECT_0:
118  return true;
119  case WAIT_OBJECT_0 + 1:
120  throw exception_aborted();
121  case WAIT_OBJECT_0 + 2:
123  break;
124  case WAIT_FAILED:
125  WIN32_OP_FAIL();
126  default:
127  uBugCheck();
128  }
129  }
130  }
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL()
Definition: win32_misc.cpp:52
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
PFC_NORETURN void SHARED_EXPORT uBugCheck()
static void ProcessPendingMessages()
Definition: ThreadUtils.h:21