mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
FancyZones and Shortcut Guide initial commit
Co-authored-by: Alexis Campailla <alexis@janeasystems.com> Co-authored-by: Bret Anderson <bretan@microsoft.com> Co-authored-by: Enrico Giordani <enrico.giordani@gmail.com> Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Jeff Bogdan <jeffbog@microsoft.com> Co-authored-by: March Rogers <marchr@microsoft.com> Co-authored-by: Mike Harsh <mharsh@microsoft.com> Co-authored-by: Nachum Bundak <Nachum.Bundak@microsoft.com> Co-authored-by: Oliver Jones <ojones@microsoft.com> Co-authored-by: Patrick Little <plittle@microsoft.com>
This commit is contained in:
committed by
Bartosz Sosnowski
parent
10c5396099
commit
8431b80e48
47
src/common/async_message_queue.h
Normal file
47
src/common/async_message_queue.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <string>
|
||||
|
||||
class AsyncMessageQueue {
|
||||
private:
|
||||
std::mutex queue_mutex;
|
||||
std::queue<std::wstring> message_queue;
|
||||
std::condition_variable message_ready;
|
||||
bool interrupted = false;
|
||||
|
||||
//Disable copy
|
||||
AsyncMessageQueue(const AsyncMessageQueue&);
|
||||
AsyncMessageQueue& operator=(const AsyncMessageQueue&);
|
||||
|
||||
public:
|
||||
AsyncMessageQueue() {
|
||||
}
|
||||
void queue_message(std::wstring message) {
|
||||
this->queue_mutex.lock();
|
||||
this->message_queue.push(message);
|
||||
this->queue_mutex.unlock();
|
||||
this->message_ready.notify_one();
|
||||
}
|
||||
std::wstring pop_message() {
|
||||
std::unique_lock<std::mutex> lock(this->queue_mutex);
|
||||
while (message_queue.empty() && !this->interrupted) {
|
||||
this->message_ready.wait(lock);
|
||||
}
|
||||
if (this->interrupted) {
|
||||
//Just returns a empty string if the queue was interrupted.
|
||||
return std::wstring(L"");
|
||||
}
|
||||
std::wstring message = this->message_queue.front();
|
||||
this->message_queue.pop();
|
||||
return message;
|
||||
}
|
||||
void interrupt() {
|
||||
this->queue_mutex.lock();
|
||||
this->interrupted = true;
|
||||
this->queue_mutex.unlock();
|
||||
this->message_ready.notify_all();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user