From fa4d2d9b2ea5446098748e0d5700a8c3ceeea955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 11 Jul 2011 23:07:42 +0200 Subject: [PATCH] Removed some silly data races from using cerr... --- CMakeLists.txt | 2 +- library/Core.cpp | 13 ------------- library/FakeSDL-linux.cpp | 9 +++++++-- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 175542cc6..645032caf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # main project file. use it from a build sub-folder, see COMPILE for details ## some generic CMake magic -cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR) +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) project(dfhack) SET(CMAKE_MODULE_PATH diff --git a/library/Core.cpp b/library/Core.cpp index 010017edb..5b0273681 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -323,17 +323,11 @@ void Core::Resume() } // should always be from simulation thread! -static bool flip2 = false; int Core::Update() { if(!started) Init(); if(errorstate) 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 plug_mgr->OnUpdate(); @@ -380,16 +374,10 @@ int Core::Shutdown ( void ) return -1; } -static bool flip3 = 0; int Core::SDL_Event(SDL::Event* ev, int orig_return) { // do NOT process events before we are ready. if(!started) return orig_return; - if(!flip3) - { - std::cerr << "Event from Thread " << SDL_ThreadID() << std::endl; - flip3 = true; - } if(!ev) return orig_return; 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; else { - std::cerr << "Hotkey " << idx << " triggered. Thread " << SDL_ThreadID() << std::endl; t_hotkey & hotkey = (*g->hotkeys)[idx]; setHotkeyCmd(hotkey.name); } diff --git a/library/FakeSDL-linux.cpp b/library/FakeSDL-linux.cpp index 484970dc0..17dd0b5f9 100644 --- a/library/FakeSDL-linux.cpp +++ b/library/FakeSDL-linux.cpp @@ -76,9 +76,12 @@ bool inited = false; DFhackCExport int SDL_NumJoysticks(void) { - inited = true; 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 @@ -162,6 +165,8 @@ DFhackCExport int SDL_PollEvent(SDL::Event* event) // 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 // 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) { DFHack::Core & c = DFHack::Core::getInstance();