diff options
Diffstat (limited to '')
| -rw-r--r-- | CPP/Windows/Synchronization.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/CPP/Windows/Synchronization.cpp b/CPP/Windows/Synchronization.cpp new file mode 100644 index 0000000..fbf919d --- /dev/null +++ b/CPP/Windows/Synchronization.cpp | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | // Windows/Synchronization.cpp | ||
| 2 | |||
| 3 | #include "StdAfx.h" | ||
| 4 | |||
| 5 | #ifndef _WIN32 | ||
| 6 | |||
| 7 | #include "Synchronization.h" | ||
| 8 | |||
| 9 | namespace NWindows { | ||
| 10 | namespace NSynchronization { | ||
| 11 | |||
| 12 | /* | ||
| 13 | #define INFINITE 0xFFFFFFFF | ||
| 14 | #define MAXIMUM_WAIT_OBJECTS 64 | ||
| 15 | #define STATUS_ABANDONED_WAIT_0 ((NTSTATUS)0x00000080L) | ||
| 16 | #define WAIT_ABANDONED ((STATUS_ABANDONED_WAIT_0 ) + 0 ) | ||
| 17 | #define WAIT_ABANDONED_0 ((STATUS_ABANDONED_WAIT_0 ) + 0 ) | ||
| 18 | // WINAPI | ||
| 19 | DWORD WaitForMultipleObjects(DWORD count, const HANDLE *handles, BOOL wait_all, DWORD timeout); | ||
| 20 | */ | ||
| 21 | |||
| 22 | DWORD WINAPI WaitForMultiObj_Any_Infinite(DWORD count, const CHandle_WFMO *handles) | ||
| 23 | { | ||
| 24 | if (count < 1) | ||
| 25 | { | ||
| 26 | // abort(); | ||
| 27 | SetLastError(EINVAL); | ||
| 28 | return WAIT_FAILED; | ||
| 29 | } | ||
| 30 | |||
| 31 | CSynchro *synchro = handles[0]->_sync; | ||
| 32 | synchro->Enter(); | ||
| 33 | |||
| 34 | // #ifdef DEBUG_SYNCHRO | ||
| 35 | for (DWORD i = 1; i < count; i++) | ||
| 36 | { | ||
| 37 | if (synchro != handles[i]->_sync) | ||
| 38 | { | ||
| 39 | // abort(); | ||
| 40 | synchro->Leave(); | ||
| 41 | SetLastError(EINVAL); | ||
| 42 | return WAIT_FAILED; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | // #endif | ||
| 46 | |||
| 47 | for (;;) | ||
| 48 | { | ||
| 49 | for (DWORD i = 0; i < count; i++) | ||
| 50 | { | ||
| 51 | if (handles[i]->IsSignaledAndUpdate()) | ||
| 52 | { | ||
| 53 | synchro->Leave(); | ||
| 54 | return WAIT_OBJECT_0 + i; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | synchro->WaitCond(); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | }} | ||
| 62 | |||
| 63 | #endif | ||
