Skip to content
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

Alternative fix for the memory blowup issue. #8105

Draft
wants to merge 7 commits into
base: ue5-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Doxygen/
Dist/
out/

.clangd
CMakeSettings.json

Help.md
8 changes: 4 additions & 4 deletions LibCarla/source/carla/AtomicList.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ namespace detail {

template <typename ValueT>
void Push(ValueT &&value) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
auto new_list = std::make_shared<ListT>(*Load());
new_list->emplace_back(std::forward<ValueT>(value));
_list = new_list;
}

void DeleteByIndex(size_t index) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
auto new_list = std::make_shared<ListT>(*Load());
auto begin = new_list->begin();
std::advance(begin, index);
Expand All @@ -47,14 +47,14 @@ namespace detail {

template <typename ValueT>
void DeleteByValue(const ValueT &value) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
auto new_list = std::make_shared<ListT>(*Load());
new_list->erase(std::remove(new_list->begin(), new_list->end(), value), new_list->end());
_list = new_list;
}

void Clear() {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
_list = std::make_shared<ListT>();
}

Expand Down
2 changes: 1 addition & 1 deletion LibCarla/source/carla/RecurrentSharedFuture.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace detail {
template <typename T>
template <typename T2>
void RecurrentSharedFuture<T>::SetValue(const T2 &value) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
for (auto &pair : _map) {
pair.second.should_wait = false;
pair.second.value = value;
Expand Down
16 changes: 8 additions & 8 deletions LibCarla/source/carla/client/LightManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,31 +216,31 @@ bool LightManager::IsActive(LightId id) const {
}

void LightManager::SetActive(LightId id, bool active) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
LightState& state = const_cast<LightState&>(RetrieveLightState(id));
state._active = active;
_lights_changes[id] = state;
_dirty = true;
}

void LightManager::SetColor(LightId id, Color color) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
LightState& state = const_cast<LightState&>(RetrieveLightState(id));
state._color = color;
_lights_changes[id] = state;
_dirty = true;
}

void LightManager::SetIntensity(LightId id, float intensity) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
LightState& state = const_cast<LightState&>(RetrieveLightState(id));
state._intensity = intensity;
_lights_changes[id] = state;
_dirty = true;
}

void LightManager::SetLightState(LightId id, const LightState& new_state) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
LightState& state = const_cast<LightState&>(RetrieveLightState(id));
state = new_state;
_lights_changes[id] = state;
Expand All @@ -254,7 +254,7 @@ void LightManager::SetLightStateNoLock(LightId id, const LightState& new_state)
}

void LightManager::SetLightGroup(LightId id, LightGroup group) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
LightState& state = const_cast<LightState&>(RetrieveLightState(id));
state._group = group;
_lights_changes[id] = state;
Expand All @@ -271,7 +271,7 @@ const LightState& LightManager::RetrieveLightState(LightId id) const {
}

void LightManager::QueryLightsStateToServer() {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
// Send blocking query
std::vector<rpc::LightState> lights_snapshot = _episode.Lock()->QueryLightsStateToServer();

Expand All @@ -294,7 +294,7 @@ void LightManager::QueryLightsStateToServer() {
}

void LightManager::UpdateServerLightsState(bool discard_client) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);

if(_dirty) {
std::vector<rpc::LightState> message;
Expand All @@ -321,7 +321,7 @@ void LightManager::UpdateServerLightsState(bool discard_client) {
}

void LightManager::ApplyChanges() {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
for(const auto& it : _lights_changes) {
SetLightStateNoLock(it.first, it.second);
}
Expand Down
12 changes: 6 additions & 6 deletions LibCarla/source/carla/client/detail/CachedActorList.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace detail {
// ===========================================================================

inline void CachedActorList::Insert(rpc::Actor actor) {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
auto id = actor.id;
_actors.emplace(id, std::move(actor));
}
Expand All @@ -78,23 +78,23 @@ namespace detail {
auto make_iterator = [&make_a_pair](auto it) {
return boost::make_transform_iterator(std::make_move_iterator(it), make_a_pair);
};
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
_actors.insert(make_iterator(std::begin(range)), make_iterator(std::end(range)));
}

template <typename RangeT>
inline std::vector<ActorId> CachedActorList::GetMissingIds(const RangeT &range) const {
std::vector<ActorId> result;
result.reserve(range.size());
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
std::copy_if(std::begin(range), std::end(range), std::back_inserter(result), [this](auto id) {
return _actors.find(id) == _actors.end();
});
return result;
}

inline std::optional<rpc::Actor> CachedActorList::GetActorById(ActorId id) const {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
auto it = _actors.find(id);
if (it != _actors.end()) {
return it->second;
Expand All @@ -106,7 +106,7 @@ namespace detail {
inline std::vector<rpc::Actor> CachedActorList::GetActorsById(const RangeT &range) const {
std::vector<rpc::Actor> result;
result.reserve(range.size());
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
for (auto &&id : range) {
auto it = _actors.find(id);
if (it != _actors.end()) {
Expand All @@ -117,7 +117,7 @@ namespace detail {
}

inline void CachedActorList::Clear() {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
_actors.clear();
}

Expand Down
16 changes: 8 additions & 8 deletions LibCarla/source/carla/multigpu/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Router::SetCallbacks() {
[=](std::shared_ptr<carla::multigpu::Primary> session, carla::Buffer buffer) {
auto self = weak.lock();
if (!self) return;
std::scoped_lock<std::mutex> lock(self->_mutex);
std::scoped_lock lock(self->_mutex);
auto prom =self-> _promises.find(session.get());
if (prom != self->_promises.end()) {
log_info("Got data from secondary (with promise): ", buffer.size());
Expand Down Expand Up @@ -85,7 +85,7 @@ boost::asio::ip::tcp::endpoint Router::GetLocalEndpoint() const {

void Router::ConnectSession(std::shared_ptr<Primary> session) {
DEBUG_ASSERT(session != nullptr);
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
_sessions.emplace_back(std::move(session));
log_info("Connected secondary servers:", _sessions.size());
// run external callback for new connections
Expand All @@ -95,7 +95,7 @@ void Router::ConnectSession(std::shared_ptr<Primary> session) {

void Router::DisconnectSession(std::shared_ptr<Primary> session) {
DEBUG_ASSERT(session != nullptr);
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
if (_sessions.size() == 0) return;
_sessions.erase(
std::remove(_sessions.begin(), _sessions.end(), session),
Expand All @@ -104,7 +104,7 @@ void Router::DisconnectSession(std::shared_ptr<Primary> session) {
}

void Router::ClearSessions() {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
_sessions.clear();
log_info("Disconnecting all secondary servers");
}
Expand All @@ -121,7 +121,7 @@ void Router::Write(MultiGPUCommand id, Buffer &&buffer) {
auto message = Primary::MakeMessage(view_header, view_data);

// write to multiple servers
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
for (auto &s : _sessions) {
if (s != nullptr) {
s->Write(message);
Expand All @@ -144,7 +144,7 @@ std::future<SessionInfo> Router::WriteToNext(MultiGPUCommand id, Buffer &&buffer
auto response = std::make_shared<std::promise<SessionInfo>>();

// write to the next server only
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
if (_next >= _sessions.size()) {
_next = 0;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ std::future<SessionInfo> Router::WriteToOne(std::weak_ptr<Primary> server, Multi
auto response = std::make_shared<std::promise<SessionInfo>>();

// write to the specific server only
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
auto s = server.lock();
if (s) {
_promises[s.get()] = response;
Expand All @@ -186,7 +186,7 @@ std::future<SessionInfo> Router::WriteToOne(std::weak_ptr<Primary> server, Multi
}

std::weak_ptr<Primary> Router::GetNextServer() {
std::scoped_lock<std::mutex> lock(_mutex);
std::scoped_lock lock(_mutex);
if (_next >= _sessions.size()) {
_next = 0;
}
Expand Down
Loading