#include "ipcz/api_object.h"
#include <cstdint>
#include "third_party/abseil-cpp/absl/container/flat_hash_set.h"
#include "third_party/abseil-cpp/absl/synchronization/mutex.h"
namespace ipcz {
namespace {
#if defined(LEAK_SANITIZER)
class TrackedObjectSet {
public:
TrackedObjectSet() = default;
~TrackedObjectSet() = default;
void Add(APIObject* object) {
absl::MutexLock lock(&mutex_);
tracked_objects_.insert(reinterpret_cast<uintptr_t>(object));
}
void Remove(APIObject* object) {
absl::MutexLock lock(&mutex_);
tracked_objects_.erase(reinterpret_cast<uintptr_t>(object));
}
private:
absl::Mutex mutex_;
absl::flat_hash_set<uintptr_t> tracked_objects_ ABSL_GUARDED_BY(mutex_);
};
TrackedObjectSet& GetTrackedObjectSet() {
static auto* set = new TrackedObjectSet();
return *set;
}
void TrackObject(APIObject* object) {
GetTrackedObjectSet().Add(object);
}
void UntrackObject(APIObject* object) {
GetTrackedObjectSet().Remove(object);
}
#else
void TrackObject(APIObject*) { … }
void UntrackObject(APIObject*) { … }
#endif
}
APIObject::APIObject(ObjectType type) : … { … }
APIObject::~APIObject() { … }
bool APIObject::CanSendFrom(Router& sender) { … }
}