1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #include "common/scummsys.h"
25 
26 #if defined(SDL_BACKEND)
27 
28 #include "backends/timer/sdl/sdl-timer.h"
29 
30 #include "common/textconsole.h"
31 
32 OSystem::MutexRef timerMutex;
33 
timer_handler(Uint32 interval,void * param)34 static Uint32 timer_handler(Uint32 interval, void *param) {
35 	Common::StackLock lock(timerMutex);
36 
37 	((DefaultTimerManager *)param)->handler();
38 	return interval;
39 }
40 
SdlTimerManager()41 SdlTimerManager::SdlTimerManager() {
42 	// Initializes the SDL timer subsystem
43 	if (SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
44 		error("Could not initialize SDL: %s", SDL_GetError());
45 	}
46 
47 	// Creates the timer callback
48 	_timerID = SDL_AddTimer(10, &timer_handler, this);
49 }
50 
~SdlTimerManager()51 SdlTimerManager::~SdlTimerManager() {
52 	Common::StackLock lock(timerMutex);
53 
54 	// Removes the timer callback
55 	SDL_RemoveTimer(_timerID);
56 
57 	SDL_QuitSubSystem(SDL_INIT_TIMER);
58 }
59 
60 #endif
61