aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2022-05-25 17:26:26 +0200
committervaxerski <[email protected]>2022-05-25 17:26:26 +0200
commitb2769bab68d7eb6ea4460edaf910715f9f00829f (patch)
treeb978e158024c113836299a8ffaee21e4732fe5f8 /src
parentedac77abebb2baa10b6f608103c1da5e546cd825 (diff)
downloadHyprland-b2769bab68d7eb6ea4460edaf910715f9f00829f.tar.gz
Hyprland-b2769bab68d7eb6ea4460edaf910715f9f00829f.zip
use mutexes in eventmanager like a normal human
Diffstat (limited to 'src')
-rw-r--r--src/managers/EventManager.cpp32
-rw-r--r--src/managers/EventManager.hpp4
2 files changed, 10 insertions, 26 deletions
diff --git a/src/managers/EventManager.cpp b/src/managers/EventManager.cpp
index cd6cabba..a8bde442 100644
--- a/src/managers/EventManager.cpp
+++ b/src/managers/EventManager.cpp
@@ -48,7 +48,6 @@ void CEventManager::startThread() {
fcntl(SOCKET, F_SETFL, flags | O_NONBLOCK);
while (1) {
- m_bCanWriteEventQueue = true;
const auto ACCEPTEDCONNECTION = accept(SOCKET, (sockaddr*)&clientAddress, &clientSize);
@@ -78,15 +77,11 @@ void CEventManager::startThread() {
// valid FDs, check the queue
// don't do anything if main thread is writing to the eventqueue
- while (!m_bCanReadEventQueue) {
- std::this_thread::sleep_for(std::chrono::milliseconds(1));
- }
-
- // if we got here, we'll be reading the queue, let's disallow writing
- m_bCanWriteEventQueue = false;
+ eventQueueMutex.lock();
if (m_dQueuedEvents.empty()){ // if queue empty, sleep and ignore
std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ eventQueueMutex.unlock();
continue;
}
@@ -100,7 +95,7 @@ void CEventManager::startThread() {
m_dQueuedEvents.clear();
- m_bCanWriteEventQueue = true;
+ eventQueueMutex.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
@@ -110,20 +105,9 @@ void CEventManager::startThread() {
}
void CEventManager::postEvent(const SHyprIPCEvent event) {
-
- m_bCanReadEventQueue = false;
- if (!m_bCanWriteEventQueue) {
- // if we can't write rn, make a thread to write whenever possible, don't block calling events.
- std::thread([&](const SHyprIPCEvent ev) {
- while(!m_bCanWriteEventQueue) {
- std::this_thread::sleep_for(std::chrono::microseconds(200));
- }
-
- m_dQueuedEvents.push_back(ev);
- m_bCanReadEventQueue = true;
- }, event).detach();
- } else {
- m_dQueuedEvents.push_back(event);
- m_bCanReadEventQueue = true;
- }
+ std::thread([&](const SHyprIPCEvent ev) {
+ eventQueueMutex.lock();
+ m_dQueuedEvents.push_back(ev);
+ eventQueueMutex.unlock();
+ }, event).detach();
} \ No newline at end of file
diff --git a/src/managers/EventManager.hpp b/src/managers/EventManager.hpp
index b5c4d3a6..f8ec6afc 100644
--- a/src/managers/EventManager.hpp
+++ b/src/managers/EventManager.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <deque>
#include <fstream>
+#include <mutex>
#include "../defines.hpp"
#include "../helpers/MiscFunctions.hpp"
@@ -20,8 +21,7 @@ public:
private:
- bool m_bCanReadEventQueue = true;
- bool m_bCanWriteEventQueue = true;
+ std::mutex eventQueueMutex;
std::deque<SHyprIPCEvent> m_dQueuedEvents;
std::deque<int> m_dAcceptedSocketFDs;