winAsync.cpp

Engine/source/platformWin32/winAsync.cpp

More...

Public Defines

define
_WIN32_WINNT() 0x501

Detailed Description

Public Defines

_WIN32_WINNT() 0x501
 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24// For VS2005.
25#define _WIN32_WINNT 0x501
26#include "platformWin32/platformWin32.h"
27#include "platform/async/asyncUpdate.h"
28
29
30AsyncUpdateThread::AsyncUpdateThread( String name, AsyncUpdateList* updateList )
31   : Parent( 0, 0, false, false ),
32     mUpdateList( updateList ),
33     mName( name )
34{
35   // Create an auto-reset event in non-signaled state.
36   mUpdateEvent = CreateEvent( NULL, false, false, NULL );
37}
38
39AsyncUpdateThread::~AsyncUpdateThread()
40{
41   CloseHandle( ( HANDLE ) mUpdateEvent );
42}
43
44void AsyncUpdateThread::_waitForEventAndReset()
45{
46   WaitForSingleObject( ( HANDLE ) mUpdateEvent, INFINITE );
47}
48
49void AsyncUpdateThread::triggerUpdate()
50{
51   SetEvent( ( HANDLE ) mUpdateEvent );
52}
53
54AsyncPeriodicUpdateThread::AsyncPeriodicUpdateThread( String name,
55                                                      AsyncUpdateList* updateList,
56                                                      U32 intervalMS )
57   : Parent( name, updateList )
58{
59   mUpdateTimer = CreateWaitableTimer( NULL, FALSE, NULL );
60
61   // This is a bit contrived.  The 'dueTime' is in 100 nanosecond intervals
62   // and relative if it is negative.  The period is in milliseconds.
63   mIntervalMS = intervalMS;
64
65   LARGE_INTEGER deltaTime;
66   deltaTime.QuadPart = - LONGLONG( intervalMS * 10 /* micro */ * 1000 /* milli */ );
67
68   SetWaitableTimer( ( HANDLE ) mUpdateTimer, &deltaTime, intervalMS, NULL, NULL, FALSE );
69}
70
71AsyncPeriodicUpdateThread::~AsyncPeriodicUpdateThread()
72{
73   CloseHandle( ( HANDLE ) mUpdateTimer );
74}
75
76void AsyncPeriodicUpdateThread::_waitForEventAndReset()
77{
78   HANDLE handles[ 2 ];
79   
80   handles[ 0 ] = ( HANDLE ) mUpdateEvent;
81   handles[ 1 ] = ( HANDLE ) mUpdateTimer;
82
83   WaitForMultipleObjects( 2, handles, FALSE, INFINITE );
84}
85