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

View File

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