Skip to content

Commit

Permalink
Fixed the issue where the decoder was blocking during creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Keukhan committed Nov 27, 2024
1 parent d605dfc commit 509f773
Showing 1 changed file with 11 additions and 32 deletions.
43 changes: 11 additions & 32 deletions src/projects/base/ovlibrary/future.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mutex>
#include <condition_variable>
#include <chrono>

namespace ov
{

class Future
{
public:
void Stop()
{
std::unique_lock<decltype(_mutex)> lock(_mutex);

std::unique_lock<std::mutex> lock(_mutex);
_stop_flag = true;

_condition.notify_all();
}

// template <typename T>
bool Submit(bool result)
{
std::unique_lock<decltype(_mutex)> lock(_mutex);

std::unique_lock<std::mutex> lock(_mutex);
_result = result;
_stop_flag = true;
_condition.notify_all();

return _result;
}

// template <typename T>
bool Get()
{
std::unique_lock<decltype(_mutex)> lock(_mutex);
std::unique_lock<std::mutex> 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 <typename T>
bool GetFor(uint32_t timeout_delta_msec)
{
std::unique_lock<decltype(_mutex)> 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<std::mutex> lock(_mutex);

if (_stop_flag)
if (!_condition.wait_for(lock, std::chrono::milliseconds(timeout_delta_msec), [this]() { return _stop_flag; }))
{
return false;
}
Expand All @@ -81,4 +60,4 @@ namespace ov
bool _stop_flag = false;
bool _result = false;
};
}
} // namespace ov

0 comments on commit 509f773

Please sign in to comment.