From 509f773548ab53862b09e2baec47bc03da393d60 Mon Sep 17 00:00:00 2001 From: Keukhan Date: Wed, 27 Nov 2024 22:33:19 +0900 Subject: [PATCH] Fixed the issue where the decoder was blocking during creation --- src/projects/base/ovlibrary/future.h | 43 +++++++--------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/projects/base/ovlibrary/future.h b/src/projects/base/ovlibrary/future.h index bd280e32e..42310c796 100644 --- a/src/projects/base/ovlibrary/future.h +++ b/src/projects/base/ovlibrary/future.h @@ -2,72 +2,51 @@ // // OvenMediaEngine // -// Created by getroot -// Copyright (c) 2018 AirenSoft. All rights reserved. +// Created by Kwon Keuk Han +// Copyright (c) 2024 AirenSoft. All rights reserved. // //============================================================================== #pragma once #include #include +#include namespace ov { - class Future { public: void Stop() { - std::unique_lock lock(_mutex); - + std::unique_lock lock(_mutex); _stop_flag = true; - _condition.notify_all(); } - // template bool Submit(bool result) { - std::unique_lock lock(_mutex); - + std::unique_lock lock(_mutex); _result = result; + _stop_flag = true; _condition.notify_all(); - return _result; } - // template bool Get() { - std::unique_lock lock(_mutex); + std::unique_lock lock(_mutex); - _condition.wait(lock); - - if (_stop_flag) - { - return false; - } + _condition.wait(lock, [this]() { return _stop_flag; }); return _result; } - // return false : timed out, return true : signalled - // template bool GetFor(uint32_t timeout_delta_msec) { - std::unique_lock lock(_mutex); - - while (!_stop_flag) - { - auto result = _condition.wait_for(lock, std::chrono::milliseconds(timeout_delta_msec)); - if (result == std::cv_status::timeout) - { - return false; - } - } + std::unique_lock lock(_mutex); - if (_stop_flag) + if (!_condition.wait_for(lock, std::chrono::milliseconds(timeout_delta_msec), [this]() { return _stop_flag; })) { return false; } @@ -81,4 +60,4 @@ namespace ov bool _stop_flag = false; bool _result = false; }; -} \ No newline at end of file +} // namespace ov \ No newline at end of file