-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(LibCarla): port core bug fixes from ue4-dev #9585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ue5-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,10 @@ | |
|
|
||
| #include <rpc/server.h> | ||
|
|
||
youtalk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <chrono> | ||
| #include <atomic> | ||
| #include <future> | ||
| #include <stdexcept> | ||
|
|
||
| namespace carla { | ||
| namespace rpc { | ||
|
|
@@ -62,6 +65,7 @@ namespace rpc { | |
|
|
||
| /// @warning does not stop the game thread. | ||
| void Stop() { | ||
| _shutdown_in_progress = true; | ||
| _server.stop(); | ||
| } | ||
|
|
||
|
|
@@ -70,6 +74,7 @@ namespace rpc { | |
| boost::asio::io_context _sync_io_context; | ||
|
|
||
| ::rpc::server _server; | ||
| std::atomic_bool _shutdown_in_progress{false}; | ||
| }; | ||
|
|
||
| // =========================================================================== | ||
|
|
@@ -106,8 +111,8 @@ namespace detail { | |
| /// I.e., we can use the io_context to run tasks on a specific thread (e.g. | ||
| /// game thread). | ||
| template <typename FuncT> | ||
| static auto WrapSyncCall(boost::asio::io_context &io, FuncT &&functor) { | ||
| return [&io, functor=std::forward<FuncT>(functor)](Metadata metadata, Args... args) -> R { | ||
| static auto WrapSyncCall(std::atomic_bool &shutdown_in_progress, boost::asio::io_context &io, FuncT &&functor) { | ||
| return [&shutdown_in_progress, &io, functor=std::forward<FuncT>(functor)](Metadata metadata, Args... args) -> R { | ||
| auto task = std::packaged_task<R()>([functor=std::move(functor), args...]() { | ||
| return functor(args...); | ||
| }); | ||
|
|
@@ -119,7 +124,15 @@ namespace detail { | |
| // Post task and wait for result. | ||
| auto result = task.get_future(); | ||
| boost::asio::post(io, MoveHandler(task)); | ||
| return result.get(); | ||
| std::future_status status; | ||
| do { | ||
| status = result.wait_for(std::chrono::milliseconds(100)); | ||
| } while (!shutdown_in_progress && (status != std::future_status::ready)); | ||
| if (status == std::future_status::ready) { | ||
| return result.get(); | ||
| } else { | ||
| throw std::runtime_error("RPC server is shutting down"); | ||
| } | ||
|
Comment on lines
+127
to
+135
|
||
| } | ||
| }; | ||
| } | ||
|
|
@@ -153,7 +166,7 @@ namespace detail { | |
| using Wrapper = detail::FunctionWrapper<FunctorT>; | ||
| _server.bind( | ||
| name, | ||
| Wrapper::WrapSyncCall(_sync_io_context, std::forward<FunctorT>(functor))); | ||
| Wrapper::WrapSyncCall(_shutdown_in_progress, _sync_io_context, std::forward<FunctorT>(functor))); | ||
| } | ||
|
|
||
| template <typename FunctorT> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.