Skip to content

Commit

Permalink
conntrack: replace std::mutex with Thread::MutexBasicLockable
Browse files Browse the repository at this point in the history
Upstream Envoy linting prevents usages of `std::mutex` in favor of
`Thread::MutexBasicLockable`.

See https://github.com/envoyproxy/envoy/blob/main/tools/code_format/check_format.py#L605-L610

```
report_error(
  "Don't use <mutex> or <condition_variable*>, switch to "
  "Thread::MutexBasicLockable in source/common/common/thread.h")
```

This error occurred while trying to cleanup the imports - and therefore
adding the direct dependency to `<mutex>`.

See #1089

Signed-off-by: Marco Hofstetter <[email protected]>
  • Loading branch information
mhofstetter committed Jan 3, 2025
1 parent dfaf444 commit 0430df5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions cilium/conntrack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "envoy/common/platform.h"

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

#include "linux/bpf.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

0 comments on commit 0430df5

Please sign in to comment.