lib/platform: Use standard mutex primitives in Windows desks code

This commit is contained in:
Povilas Kanapickas 2021-11-03 02:58:36 +02:00
parent da673de27c
commit 2655e4cca6
2 changed files with 14 additions and 19 deletions

View File

@ -22,7 +22,6 @@
#include "platform/MSWindowsScreen.h" #include "platform/MSWindowsScreen.h"
#include "barrier/IScreenSaver.h" #include "barrier/IScreenSaver.h"
#include "barrier/XScreen.h" #include "barrier/XScreen.h"
#include "mt/Lock.h"
#include "mt/Thread.h" #include "mt/Thread.h"
#include "arch/win32/ArchMiscWindows.h" #include "arch/win32/ArchMiscWindows.h"
#include "base/Log.h" #include "base/Log.h"
@ -110,8 +109,6 @@ MSWindowsDesks::MSWindowsDesks(bool isPrimary, bool noHooks,
m_screensaverNotify(false), m_screensaverNotify(false),
m_activeDesk(NULL), m_activeDesk(NULL),
m_activeDeskName(), m_activeDeskName(),
m_mutex(),
m_deskReady(&m_mutex, false),
m_updateKeys(updateKeys), m_updateKeys(updateKeys),
m_events(events), m_events(events),
m_stopOnDeskSwitch(stopOnDeskSwitch) m_stopOnDeskSwitch(stopOnDeskSwitch)
@ -623,9 +620,9 @@ void MSWindowsDesks::desk_thread(Desk* desk)
// tell main thread that we're ready // tell main thread that we're ready
{ {
Lock lock(&m_mutex); std::lock_guard<std::mutex> lock(mutex_);
m_deskReady = true; is_desks_ready_ = true;
m_deskReady.broadcast(); desks_ready_cv_.notify_all();
} }
while (GetMessage(&msg, NULL, 0, 0)) { while (GetMessage(&msg, NULL, 0, 0)) {
@ -725,9 +722,9 @@ void MSWindowsDesks::desk_thread(Desk* desk)
} }
// notify that message was processed // notify that message was processed
Lock lock(&m_mutex); std::lock_guard<std::mutex> lock(mutex_);
m_deskReady = true; is_desks_ready_ = true;
m_deskReady.broadcast(); desks_ready_cv_.notify_all();
} }
// clean up // clean up
@ -855,11 +852,9 @@ MSWindowsDesks::waitForDesk() const
{ {
MSWindowsDesks* self = const_cast<MSWindowsDesks*>(this); MSWindowsDesks* self = const_cast<MSWindowsDesks*>(this);
Lock lock(&m_mutex); std::unique_lock<std::mutex> lock(mutex_);
while (!(bool)m_deskReady) { desks_ready_cv_.wait(lock, [this](){ return is_desks_ready_; });
m_deskReady.wait(); self->is_desks_ready_ = false;
}
self->m_deskReady = false;
} }
void void

View File

@ -23,16 +23,15 @@
#include "barrier/key_types.h" #include "barrier/key_types.h"
#include "barrier/mouse_types.h" #include "barrier/mouse_types.h"
#include "barrier/option_types.h" #include "barrier/option_types.h"
#include "mt/CondVar.h"
#include "mt/Mutex.h"
#include "common/stdmap.h" #include "common/stdmap.h"
#include <condition_variable>
#include <functional> #include <functional>
#include <mutex>
#include <string> #include <string>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
class Event; class Event;
class EventQueueTimer; class EventQueueTimer;
class Thread; class Thread;
@ -280,8 +279,9 @@ private:
std::string m_activeDeskName; std::string m_activeDeskName;
// one desk per desktop and a cond var to communicate with it // one desk per desktop and a cond var to communicate with it
Mutex m_mutex; mutable std::mutex mutex_;
CondVar<bool> m_deskReady; mutable std::condition_variable desks_ready_cv_;
bool is_desks_ready_ = false;
Desks m_desks; Desks m_desks;
// keyboard stuff // keyboard stuff