2025-08-30 13:27:30 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-11-21 11:31:18 -05:00
|
|
|
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
//
|
|
|
|
// TODO: remove this file when jthread is supported by all compilation targets
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-01-25 16:03:32 -05:00
|
|
|
#include <chrono>
|
|
|
|
#include <condition_variable>
|
2022-11-21 11:31:18 -05:00
|
|
|
#include <thread>
|
2023-10-13 18:51:11 +03:00
|
|
|
#include <utility>
|
2022-11-21 11:31:18 -05:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
2023-01-25 16:03:32 -05:00
|
|
|
template <typename Rep, typename Period>
|
|
|
|
bool StoppableTimedWait(std::stop_token token, const std::chrono::duration<Rep, Period>& rel_time) {
|
|
|
|
std::condition_variable_any cv;
|
|
|
|
std::mutex m;
|
|
|
|
|
|
|
|
// Perform the timed wait.
|
|
|
|
std::unique_lock lk{m};
|
|
|
|
return !cv.wait_for(lk, token, rel_time, [&] { return token.stop_requested(); });
|
|
|
|
}
|
|
|
|
|
2022-11-21 11:31:18 -05:00
|
|
|
} // namespace Common
|