mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-20 06:47:56 +08:00
c93eb92cd0
* rename dll -> FancyZonesModuleInterface (#11488) * [FancyZones] Rename "fancyzones/tests" -> "fancyzones/FancyZonesTests" (#11492) * [FancyZones] Rename "fancyzones/lib" -> "fancyzones/FancyZonesLib" (#11489) * [FancyZones] New FancyZones project. (#11544) * [FancyZones] Allow single instance of "PowerToys.FancyZones.exe" (#11558) * [FancyZones] Updated bug reports (#11571) * [FancyZones] Updated installer (#11572) * [FancyZones] Update string resources (#11596) * [FancyZones] Terminate FancyZones with runner (#11696) * [FancyZones] Drop support for the module interface API to save settings (#11661) * Settings telemetry for FancyZones (#11766) * commented out test * enable dpi awareness for the process
32 lines
768 B
C++
32 lines
768 B
C++
#pragma once
|
|
|
|
#include <future>
|
|
#include <thread>
|
|
#include <functional>
|
|
#include <queue>
|
|
#include <atomic>
|
|
|
|
// OnThreadExecutor allows its caller to off-load some work to a persistently running background thread.
|
|
// This might come in handy if you use the API which sets thread-wide global state and the state needs
|
|
// to be isolated.
|
|
|
|
class OnThreadExecutor final
|
|
{
|
|
public:
|
|
using task_t = std::packaged_task<void()>;
|
|
|
|
OnThreadExecutor();
|
|
~OnThreadExecutor();
|
|
std::future<void> submit(task_t task);
|
|
void cancel();
|
|
|
|
private:
|
|
void worker_thread();
|
|
|
|
std::mutex _task_mutex;
|
|
std::condition_variable _task_cv;
|
|
std::atomic_bool _shutdown_request;
|
|
std::queue<std::packaged_task<void()>> _task_queue;
|
|
std::thread _worker_thread;
|
|
};
|