Files
Library/include/Void/System/SignalWatcher.hpp
T
faumaray 3851aeb703
CI / GCC 16 / C++26 / werror (push) Failing after 3m9s
CI / GCC 16 / C++26 / sanitizers (push) Failing after 10m15s
CI / GCC 16 / C++26 / default (push) Failing after 13m1s
Update
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-20 01:18:53 +03:00

45 lines
1.3 KiB
C++

#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <chrono>
#include <memory>
#include <optional>
#include <vector>
namespace Void::Process
{
/// Converts process signals into synchronous, deterministic waits.
/// Construct this before worker threads so the selected signals inherit a
/// blocked mask. A watcher must be destroyed on the thread that created it.
class SignalWatcher
{
public:
/// An empty signal list watches SIGINT and SIGTERM.
[[nodiscard]] static Void::Result::Result<SignalWatcher>
create(std::vector<int> signals = {});
~SignalWatcher();
SignalWatcher(SignalWatcher&&) noexcept;
SignalWatcher& operator=(SignalWatcher&&) noexcept;
SignalWatcher(const SignalWatcher&) = delete;
SignalWatcher& operator=(const SignalWatcher&) = delete;
/// Wait for a configured signal. A zero timeout performs a poll;
/// milliseconds::max() waits indefinitely.
[[nodiscard]] Void::Result::Result<std::optional<int>>
wait(std::chrono::milliseconds timeout =
std::chrono::milliseconds::max());
[[nodiscard]] Void::Result::Result<std::optional<int>> poll();
private:
struct Impl;
std::unique_ptr<Impl> m_impl;
explicit SignalWatcher(std::unique_ptr<Impl> impl) noexcept;
};
} // namespace Void::Process