-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves the CoroutineRunnable from Morpheus' Sherlock feature branch to MRC and renames it to AsyncioRunnable as it is heavily dependent on asyncio. Adjustments were made such that the Scheduler would no longer own a task container and/or tasks, leaving the scheduler interface simpler. Instead, the runnable is responsible for the lifetime of the tasks it creates. This leaves the scheduler with a single responsibility. Much of the code could be moved to MRC proper from PyMRC, but it's not immediately obvious where the code should live or whether it would be reused, so keeping it colocated with the AsyncioRunnable makes the most sense for now, imo. Authors: - Christopher Harris (https://github.com/cwharris) Approvers: - Devin Robison (https://github.com/drobison00) URL: #411
- Loading branch information
Showing
10 changed files
with
929 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <exception> | ||
#include <mutex> | ||
#include <queue> | ||
|
||
#pragma once | ||
|
||
namespace mrc { | ||
|
||
/** | ||
* @brief A utility for catching out-of-stack exceptions in a thread-safe manner such that they | ||
* can be checked and throw from a parent thread. | ||
*/ | ||
class ExceptionCatcher | ||
{ | ||
public: | ||
/** | ||
* @brief "catches" an exception to the catcher | ||
*/ | ||
void push_exception(std::exception_ptr ex); | ||
|
||
/** | ||
* @brief checks to see if any exceptions have been "caught" by the catcher. | ||
*/ | ||
bool has_exception(); | ||
|
||
/** | ||
* @brief rethrows the next exception (in the order in which it was "caught"). | ||
*/ | ||
void rethrow_next_exception(); | ||
|
||
private: | ||
std::mutex m_mutex{}; | ||
std::queue<std::exception_ptr> m_exceptions{}; | ||
}; | ||
|
||
} // namespace mrc |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <mrc/exceptions/exception_catcher.hpp> | ||
|
||
namespace mrc { | ||
|
||
void ExceptionCatcher::push_exception(std::exception_ptr ex) | ||
{ | ||
auto lock = std::lock_guard(m_mutex); | ||
m_exceptions.push(ex); | ||
} | ||
|
||
bool ExceptionCatcher::has_exception() | ||
{ | ||
auto lock = std::lock_guard(m_mutex); | ||
return not m_exceptions.empty(); | ||
} | ||
|
||
void ExceptionCatcher::rethrow_next_exception() | ||
{ | ||
auto lock = std::lock_guard(m_mutex); | ||
|
||
if (m_exceptions.empty()) | ||
{ | ||
return; | ||
} | ||
|
||
auto ex = m_exceptions.front(); | ||
|
||
m_exceptions.pop(); | ||
|
||
std::rethrow_exception(ex); | ||
} | ||
|
||
} // namespace mrc |
Oops, something went wrong.