|
1
|
1 #include "foobar2000-sdk-pch.h"
|
|
|
2
|
|
|
3 #include "abort_callback.h"
|
|
|
4
|
|
|
5 void abort_callback::check() const {
|
|
|
6 if (is_aborting()) {
|
|
|
7 throw exception_aborted();
|
|
|
8 }
|
|
|
9 }
|
|
|
10
|
|
|
11 void abort_callback::sleep(double p_timeout_seconds) const {
|
|
|
12 if (!sleep_ex(p_timeout_seconds)) {
|
|
|
13 throw exception_aborted();
|
|
|
14 }
|
|
|
15 }
|
|
|
16
|
|
|
17 bool abort_callback::sleep_ex(double p_timeout_seconds) const {
|
|
|
18 // return true IF NOT SET (timeout), false if set
|
|
|
19 return !pfc::event::g_wait_for(get_abort_event(),p_timeout_seconds);
|
|
|
20 }
|
|
|
21
|
|
|
22 bool abort_callback::waitForEvent( pfc::eventHandle_t evtHandle, double timeOut ) const {
|
|
|
23 int status = pfc::event::g_twoEventWait( this->get_abort_event(), evtHandle, timeOut );
|
|
|
24 switch(status) {
|
|
|
25 case 1: throw exception_aborted();
|
|
|
26 case 2: return true;
|
|
|
27 case 0: return false;
|
|
|
28 default: uBugCheck();
|
|
|
29 }
|
|
|
30 }
|
|
|
31
|
|
|
32 bool abort_callback_usehandle::is_aborting() const {
|
|
|
33 return pfc::event::g_wait_for( get_abort_event(), 0 );
|
|
|
34 }
|
|
|
35
|
|
|
36 bool abort_callback::waitForEvent(pfc::event& evt, double timeOut) const {
|
|
|
37 return waitForEvent(evt.get_handle(), timeOut);
|
|
|
38 }
|
|
|
39
|
|
|
40 void abort_callback::waitForEvent(pfc::eventHandle_t evtHandle) const {
|
|
|
41 bool status = waitForEvent(evtHandle, -1); (void)status;
|
|
|
42 PFC_ASSERT(status); // should never return false
|
|
|
43 }
|
|
|
44
|
|
|
45 void abort_callback::waitForEvent(pfc::event& evt) const {
|
|
|
46 bool status = waitForEvent(evt, -1); (void)status;
|
|
|
47 PFC_ASSERT(status); // should never return false
|
|
|
48 }
|
|
|
49
|
|
|
50 bool abort_callback::waitForEventNoThrow(pfc::eventHandle_t evtHandle) const {
|
|
|
51 int status = pfc::event::g_twoEventWait(this->get_abort_event(), evtHandle, -1);
|
|
|
52 switch (status) {
|
|
|
53 case 1: return false;
|
|
|
54 case 2: return true;
|
|
|
55 default: uBugCheck();
|
|
|
56 }
|
|
|
57 }
|
|
|
58
|
|
|
59 bool abort_callback::waitForEventNoThrow(pfc::event& evt) const {
|
|
|
60 return waitForEventNoThrow(evt.get_handle());
|
|
|
61 }
|
|
|
62
|
|
|
63 namespace fb2k {
|
|
|
64 abort_callback_dummy noAbort;
|
|
|
65 }
|
|
|
66
|
|
|
67 abort_callback_event abort_callback_clone::clone(abort_callback_event arg) {
|
|
|
68 return pfc::fileHandleDup(arg);
|
|
|
69 }
|
|
|
70
|
|
|
71 void abort_callback_clone::close(abort_callback_event arg) {
|
|
|
72 return pfc::fileHandleClose(arg);
|
|
|
73 }
|
|
|
74
|