Removed some silly data races from using cerr...

develop
Petr Mrázek 2011-07-11 23:07:42 +02:00
parent 4015586d89
commit fa4d2d9b2e
3 changed files with 8 additions and 16 deletions

@ -1,7 +1,7 @@
# main project file. use it from a build sub-folder, see COMPILE for details # main project file. use it from a build sub-folder, see COMPILE for details
## some generic CMake magic ## some generic CMake magic
cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR) cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(dfhack) project(dfhack)
SET(CMAKE_MODULE_PATH SET(CMAKE_MODULE_PATH

@ -323,17 +323,11 @@ void Core::Resume()
} }
// should always be from simulation thread! // should always be from simulation thread!
static bool flip2 = false;
int Core::Update() int Core::Update()
{ {
if(!started) Init(); if(!started) Init();
if(errorstate) if(errorstate)
return -1; return -1;
if(!flip2)
{
std::cerr << "Update from Thread " << SDL_ThreadID() << std::endl;
flip2 = true;
}
// notify all the plugins that a game tick is finished // notify all the plugins that a game tick is finished
plug_mgr->OnUpdate(); plug_mgr->OnUpdate();
@ -380,16 +374,10 @@ int Core::Shutdown ( void )
return -1; return -1;
} }
static bool flip3 = 0;
int Core::SDL_Event(SDL::Event* ev, int orig_return) int Core::SDL_Event(SDL::Event* ev, int orig_return)
{ {
// do NOT process events before we are ready. // do NOT process events before we are ready.
if(!started) return orig_return; if(!started) return orig_return;
if(!flip3)
{
std::cerr << "Event from Thread " << SDL_ThreadID() << std::endl;
flip3 = true;
}
if(!ev) if(!ev)
return orig_return; return orig_return;
if(ev && ev->type == SDL::ET_KEYDOWN || ev->type == SDL::ET_KEYUP) if(ev && ev->type == SDL::ET_KEYDOWN || ev->type == SDL::ET_KEYUP)
@ -413,7 +401,6 @@ int Core::SDL_Event(SDL::Event* ev, int orig_return)
return orig_return; return orig_return;
else else
{ {
std::cerr << "Hotkey " << idx << " triggered. Thread " << SDL_ThreadID() << std::endl;
t_hotkey & hotkey = (*g->hotkeys)[idx]; t_hotkey & hotkey = (*g->hotkeys)[idx];
setHotkeyCmd(hotkey.name); setHotkeyCmd(hotkey.name);
} }

@ -76,9 +76,12 @@ bool inited = false;
DFhackCExport int SDL_NumJoysticks(void) DFhackCExport int SDL_NumJoysticks(void)
{ {
inited = true;
DFHack::Core & c = DFHack::Core::getInstance(); DFHack::Core & c = DFHack::Core::getInstance();
return c.Update(); // the 'inited' variable should be normally protected by a lock. It isn't
int ret = c.Update();
if(ret == 0)
inited = true;
return ret;
} }
// ptr to the real functions // ptr to the real functions
@ -162,6 +165,8 @@ DFhackCExport int SDL_PollEvent(SDL::Event* event)
// only send events to Core after we get first SDL_NumJoysticks call // only send events to Core after we get first SDL_NumJoysticks call
// DF event loop is possibly polling for SDL events before things get inited properly // DF event loop is possibly polling for SDL events before things get inited properly
// SDL handles it. We don't, because we use some other parts of SDL too. // SDL handles it. We don't, because we use some other parts of SDL too.
// possible data race. whatever. it's a flag, we don't mind all that much
if(inited && event != 0) if(inited && event != 0)
{ {
DFHack::Core & c = DFHack::Core::getInstance(); DFHack::Core & c = DFHack::Core::getInstance();