More Linux fixes

This commit is contained in:
Lynix 2020-02-23 02:49:32 +01:00
parent 3857025253
commit 6ec2f3e56e
2 changed files with 15 additions and 15 deletions

View File

@ -165,15 +165,14 @@ namespace Nz
if (m_style & WindowStyle_Threaded) if (m_style & WindowStyle_Threaded)
{ {
Mutex mutex; std::mutex mutex;
ConditionVariable condition; std::condition_variable condition;
m_threadActive = true; m_threadActive = true;
// Wait until the thread is ready // Wait until the thread is ready
mutex.Lock(); std::unique_lock<std::mutex> lock(mutex);
m_thread = Thread(WindowThread, this, &mutex, &condition); m_thread = std::string(WindowThread, this, std::ref(mutex), std::ref(condition));
condition.Wait(&mutex); condition.wait(lock);
mutex.Unlock();
} }
// Set fullscreen video mode and switch to fullscreen if necessary // Set fullscreen video mode and switch to fullscreen if necessary
@ -1577,11 +1576,12 @@ namespace Nz
)); ));
} }
void WindowImpl::WindowThread(WindowImpl* window, Mutex* mutex, ConditionVariable* condition) void WindowImpl::WindowThread(WindowImpl* window, std::mutex& mutex, std::condition_variable& condition)
{ {
mutex->Lock(); {
condition->Signal(); std::lock_guard<std::mutex> lock(mutex);
mutex->Unlock(); // mutex and condition may be destroyed after this line condition.notify_all();
}
if (!window->m_window) if (!window->m_window)
return; return;

View File

@ -10,18 +10,18 @@
#define NAZARA_WINDOWIMPL_HPP #define NAZARA_WINDOWIMPL_HPP
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Enums.hpp> #include <Nazara/Platform/Enums.hpp>
#include <Nazara/Platform/Keyboard.hpp> #include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/WindowHandle.hpp> #include <Nazara/Platform/WindowHandle.hpp>
#include <condition_variable>
#include <mutex>
#include <thread>
#include <xcb/randr.h> #include <xcb/randr.h>
#include <xcb/xcb_icccm.h> #include <xcb/xcb_icccm.h>
namespace Nz namespace Nz
{ {
class ConditionVariable;
class Mutex;
class Cursor; class Cursor;
class Icon; class Icon;
class VideoMode; class VideoMode;
@ -100,13 +100,13 @@ namespace Nz
bool UpdateNormalHints(); bool UpdateNormalHints();
void UpdateEventQueue(xcb_generic_event_t* event); void UpdateEventQueue(xcb_generic_event_t* event);
static void WindowThread(WindowImpl* window, Mutex* mutex, ConditionVariable* condition); static void WindowThread(WindowImpl* window, std::mutex& mutex, std::condition_variable& condition);
xcb_window_t m_window; xcb_window_t m_window;
xcb_screen_t* m_screen; xcb_screen_t* m_screen;
xcb_randr_get_screen_info_reply_t m_oldVideoMode; xcb_randr_get_screen_info_reply_t m_oldVideoMode;
xcb_size_hints_t m_size_hints; xcb_size_hints_t m_size_hints;
Thread m_thread; std::thread m_thread;
WindowStyleFlags m_style; WindowStyleFlags m_style;
Window* m_parent; Window* m_parent;
bool m_eventListener; bool m_eventListener;