|
| 1 | +#ifdef _WIN32 |
| 2 | +#include <Windows.h> |
| 3 | +#endif |
| 4 | +#include <cassert> |
| 5 | +#include <chrono> |
| 6 | +#include <iostream> |
| 7 | +#include <pevents.h> |
| 8 | +#include <thread> |
| 9 | + |
| 10 | +using namespace neosmart; |
| 11 | + |
| 12 | +int main() { |
| 13 | + neosmart::neosmart_event_t lEvents[3]; |
| 14 | + lEvents[0] = neosmart::CreateEvent( false, true ); // Already Signaled AutoReset |
| 15 | + lEvents[1] = neosmart::CreateEvent( false, false ); // Not Signaled AutoReset |
| 16 | + lEvents[2] = neosmart::CreateEvent( false, true ); // Already Signaled AutoReset |
| 17 | + |
| 18 | + // WFMO is non-destructive if a wait-all with any timeout value fails on auto-reset events. |
| 19 | + if ( neosmart::WaitForMultipleEvents( lEvents, 3, true, 0 ) == 0 ) |
| 20 | + throw std::runtime_error( "Must not be signaled!" ); |
| 21 | + |
| 22 | + // FAILS!! |
| 23 | + if ( neosmart::WaitForEvent( lEvents[0], 0 ) != 0 ) |
| 24 | + throw std::runtime_error( "Must be signaled" ); |
| 25 | + |
| 26 | + if ( neosmart::WaitForEvent( lEvents[1], 0 ) != WAIT_TIMEOUT ) |
| 27 | + throw std::runtime_error( "Must not be signaled" ); |
| 28 | + |
| 29 | + // FAILS!! |
| 30 | + if ( neosmart::WaitForEvent( lEvents[2], 0 ) != 0 ) |
| 31 | + throw std::runtime_error( "Must be signaled" ); |
| 32 | + |
| 33 | + |
| 34 | + // WFMO is destructive if a wait-all succeeds with any timeout value on auto-reset events. |
| 35 | + for ( auto& lEvent : lEvents ) |
| 36 | + neosmart::SetEvent( lEvent ); |
| 37 | + if ( neosmart::WaitForMultipleEvents( lEvents, 3, true, 0 ) != 0 ) // OK |
| 38 | + throw std::runtime_error( "Must be signaled!" ); |
| 39 | + for ( auto& lEvent : lEvents ) |
| 40 | + { |
| 41 | + if ( neosmart::WaitForEvent( lEvent, 0 ) != WAIT_TIMEOUT ) // OK |
| 42 | + throw std::runtime_error( "Must not be signaled" ); |
| 43 | + neosmart::DestroyEvent( lEvent ); |
| 44 | + } |
| 45 | +} |
0 commit comments