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

conntrack: replace std::mutex with Thread::MutexBasicLockable #1095

Merged
Merged
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
7 changes: 4 additions & 3 deletions cilium/conntrack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "envoy/common/platform.h"

#include "source/common/common/thread.h"
#include "source/common/common/utility.h"
#include "source/common/network/address_impl.h"

Expand Down Expand Up @@ -149,7 +150,7 @@ CtMap::openMap6(const std::string& map_name) {
}

void CtMap::closeMaps(const std::shared_ptr<absl::flat_hash_set<std::string>>& to_be_closed) {
std::lock_guard<std::mutex> guard(maps_mutex_);
std::lock_guard<Thread::MutexBasicLockable> guard(maps_mutex_);

for (const auto& name : *to_be_closed) {
auto ct4 = ct_maps4_.find(name);
Expand Down Expand Up @@ -213,7 +214,7 @@ uint32_t CtMap::lookupSrcIdentity(const std::string& map_name, const Network::Ad

if (dip->version() == Network::Address::IpVersion::v4) {
// Lock for the duration of the map lookup and conntrack lookup
std::lock_guard<std::mutex> guard(maps_mutex_);
std::lock_guard<Thread::MutexBasicLockable> guard(maps_mutex_);
auto it = ct_maps4_.find(map_name);
if (it == ct_maps4_.end()) {
it = openMap4(map_name);
Expand All @@ -231,7 +232,7 @@ uint32_t CtMap::lookupSrcIdentity(const std::string& map_name, const Network::Ad
}
} else {
// Lock for the duration of the map lookup and conntrack lookup
std::lock_guard<std::mutex> guard(maps_mutex_);
std::lock_guard<Thread::MutexBasicLockable> guard(maps_mutex_);
auto it = ct_maps6_.find(map_name);
if (it == ct_maps6_.end()) {
it = openMap6(map_name);
Expand Down
3 changes: 2 additions & 1 deletion cilium/conntrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "envoy/singleton/instance.h"

#include "source/common/common/logger.h"
#include "source/common/common/thread.h"

#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
Expand Down Expand Up @@ -70,7 +71,7 @@ class CtMap : public Singleton::Instance, Logger::Loggable<Logger::Id::filter> {

// All known conntrack maps. Populated with the "global" maps at startup,
// further maps are opened and inserted on demand.
std::mutex maps_mutex_;
Thread::MutexBasicLockable maps_mutex_;
absl::flat_hash_map<const std::string, std::unique_ptr<CtMaps4>> ct_maps4_;
absl::flat_hash_map<const std::string, std::unique_ptr<CtMaps6>> ct_maps6_;
std::string bpf_root_;
Expand Down
Loading