1*436acff3Ss.makeev_local // The MIT License (MIT) 2*436acff3Ss.makeev_local // 3*436acff3Ss.makeev_local // Copyright (c) 2015 Sergey Makeev, Vadim Slyusarev 4*436acff3Ss.makeev_local // 5*436acff3Ss.makeev_local // Permission is hereby granted, free of charge, to any person obtaining a copy 6*436acff3Ss.makeev_local // of this software and associated documentation files (the "Software"), to deal 7*436acff3Ss.makeev_local // in the Software without restriction, including without limitation the rights 8*436acff3Ss.makeev_local // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9*436acff3Ss.makeev_local // copies of the Software, and to permit persons to whom the Software is 10*436acff3Ss.makeev_local // furnished to do so, subject to the following conditions: 11*436acff3Ss.makeev_local // 12*436acff3Ss.makeev_local // The above copyright notice and this permission notice shall be included in 13*436acff3Ss.makeev_local // all copies or substantial portions of the Software. 14*436acff3Ss.makeev_local // 15*436acff3Ss.makeev_local // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16*436acff3Ss.makeev_local // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17*436acff3Ss.makeev_local // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18*436acff3Ss.makeev_local // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19*436acff3Ss.makeev_local // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20*436acff3Ss.makeev_local // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21*436acff3Ss.makeev_local // THE SOFTWARE. 22*436acff3Ss.makeev_local 23*436acff3Ss.makeev_local #pragma once 24*436acff3Ss.makeev_local 25*436acff3Ss.makeev_local #ifndef __MT_EVENT_KERNEL__ 26*436acff3Ss.makeev_local #define __MT_EVENT_KERNEL__ 27*436acff3Ss.makeev_local 28*436acff3Ss.makeev_local 29*436acff3Ss.makeev_local namespace MT 30*436acff3Ss.makeev_local { 31*436acff3Ss.makeev_local // 32*436acff3Ss.makeev_local // 33*436acff3Ss.makeev_local // 34*436acff3Ss.makeev_local class Event 35*436acff3Ss.makeev_local { 36*436acff3Ss.makeev_local ::MW_HANDLE eventHandle; 37*436acff3Ss.makeev_local 38*436acff3Ss.makeev_local public: 39*436acff3Ss.makeev_local 40*436acff3Ss.makeev_local MT_NOCOPYABLE(Event); 41*436acff3Ss.makeev_local Event()42*436acff3Ss.makeev_local Event() 43*436acff3Ss.makeev_local { 44*436acff3Ss.makeev_local static_assert(sizeof(Event) == sizeof(::MW_HANDLE), "sizeof(Event) is invalid"); 45*436acff3Ss.makeev_local eventHandle = nullptr; 46*436acff3Ss.makeev_local } 47*436acff3Ss.makeev_local Event(EventReset::Type resetType,bool initialState)48*436acff3Ss.makeev_local Event(EventReset::Type resetType, bool initialState) 49*436acff3Ss.makeev_local { 50*436acff3Ss.makeev_local eventHandle = nullptr; 51*436acff3Ss.makeev_local Create(resetType, initialState); 52*436acff3Ss.makeev_local } 53*436acff3Ss.makeev_local ~Event()54*436acff3Ss.makeev_local ~Event() 55*436acff3Ss.makeev_local { 56*436acff3Ss.makeev_local CloseHandle(eventHandle); 57*436acff3Ss.makeev_local eventHandle = nullptr; 58*436acff3Ss.makeev_local } 59*436acff3Ss.makeev_local Create(EventReset::Type resetType,bool initialState)60*436acff3Ss.makeev_local void Create(EventReset::Type resetType, bool initialState) 61*436acff3Ss.makeev_local { 62*436acff3Ss.makeev_local if (eventHandle != nullptr) 63*436acff3Ss.makeev_local { 64*436acff3Ss.makeev_local CloseHandle(eventHandle); 65*436acff3Ss.makeev_local } 66*436acff3Ss.makeev_local 67*436acff3Ss.makeev_local MW_BOOL bManualReset = (resetType == EventReset::AUTOMATIC) ? 0 : 1; 68*436acff3Ss.makeev_local MW_BOOL bInitialState = initialState ? 1 : 0; 69*436acff3Ss.makeev_local eventHandle = ::CreateEventW(nullptr, bManualReset, bInitialState, nullptr); 70*436acff3Ss.makeev_local } 71*436acff3Ss.makeev_local Signal()72*436acff3Ss.makeev_local void Signal() 73*436acff3Ss.makeev_local { 74*436acff3Ss.makeev_local SetEvent(eventHandle); 75*436acff3Ss.makeev_local } 76*436acff3Ss.makeev_local Reset()77*436acff3Ss.makeev_local void Reset() 78*436acff3Ss.makeev_local { 79*436acff3Ss.makeev_local ResetEvent(eventHandle); 80*436acff3Ss.makeev_local } 81*436acff3Ss.makeev_local Wait(uint32 milliseconds)82*436acff3Ss.makeev_local bool Wait(uint32 milliseconds) 83*436acff3Ss.makeev_local { 84*436acff3Ss.makeev_local MW_DWORD res = WaitForSingleObject(eventHandle, milliseconds); 85*436acff3Ss.makeev_local return (res == MW_WAIT_OBJECT_0); 86*436acff3Ss.makeev_local } 87*436acff3Ss.makeev_local 88*436acff3Ss.makeev_local }; 89*436acff3Ss.makeev_local 90*436acff3Ss.makeev_local } 91*436acff3Ss.makeev_local 92*436acff3Ss.makeev_local 93*436acff3Ss.makeev_local #endif 94