18 std::scoped_lock<std::mutex> lock(
_mutex);
21 std::optional<token_type> token;
23 token = server.
FindToken(it->second.stream_id);
25 log_warning(
"multigpu: stream ", it->second.stream_id,
" of actor ",
actor_id,
" no longer exists");
26 Forget(server, it->second);
43 auto &entry = it->second;
44 if (entry.primary_stream_id && (*entry.primary_stream_id != primary_stream_id)) {
47 entry.primary_stream_id = primary_stream_id;
50 token->set_stream_id(primary_stream_id);
59 std::scoped_lock<std::mutex> lock(
_mutex);
64 for (
const auto &[other_actor_id, other] :
_entries) {
65 if ((other_actor_id !=
actor_id) && (other.stream_id == sensor_stream_id)) {
67 "multigpu: actor ",
actor_id,
" replayed onto the sensor of actor ", other_actor_id,
"; not binding it");
78 auto &entry = it->second;
79 if (entry.reserved && (entry.stream_id != sensor_stream_id) && can_adopt) {
80 return std::exchange(entry.reserved, std::nullopt);
83 if (entry.stream_id != sensor_stream_id) {
84 if (entry.primary_stream_id) {
91 entry.stream_id = sensor_stream_id;
93 entry.reserved.reset();
98 std::scoped_lock<std::mutex> lock(
_mutex);
108 Forget(server, it->second);
113 std::scoped_lock<std::mutex> lock(
_mutex);
115 Forget(server, item.second);
123 std::scoped_lock<std::mutex> lock(
_mutex);
128 std::scoped_lock<std::mutex> lock(
_mutex);
133 std::scoped_lock<std::mutex> lock(
_mutex);
carla::streaming::detail::stream_id_type stream_id_type
static void Forget(carla::streaming::Server &server, const Entry &entry)
std::optional< token_type > Resolve(carla::streaming::Server &server, actor_id_type actor_id, stream_id_type primary_stream_id)
Token that serves primary actor actor_id under primary_stream_id, reserving a local stream if the sen...
epoch_type BeginEpisodeChange(carla::streaming::Server &server)
The primary switched episode: forgets every actor and returns the epoch the secondary must pass to Op...
bool IsEpisodeOpen()
Whether Bind()/Unbind() are accepted, i.e.
carla::streaming::detail::token_type token_type
void OpenEpisode(epoch_type epoch)
Accepts binding if epoch is the latest one BeginEpisodeChange() issued.
std::optional< carla::streaming::Stream > Bind(carla::streaming::Server &server, actor_id_type actor_id, stream_id_type sensor_stream_id, bool can_adopt)
Returns the stream reserved for actor_id if can_adopt (the sensor has never ticked) and the sensor mu...
std::unordered_map< actor_id_type, Entry > _entries
void Unbind(carla::streaming::Server &server, actor_id_type actor_id)
Forgets actor_id, closing its reserved stream if no sensor adopted it.
void RemoveStreamAlias(stream_id alias)
std::optional< token_type > FindToken(stream_id id)
Token of an existing stream, or std::nullopt if id is unknown.
void CloseStream(carla::streaming::detail::stream_id_type id)
void SetStreamAlias(stream_id alias, stream_id target)
const auto & get_stream_id() const
carla::streaming::detail::stream_id_type stream_id
This file contains definitions of common data structures used in traffic manager.
static void log_info(Args &&... args)
static void log_warning(Args &&... args)
std::optional< carla::streaming::Stream > reserved
std::optional< stream_id_type > primary_stream_id