#ifndef PROTON_UTILITY_SET_H_ #define PROTON_UTILITY_SET_H_ #include #include namespace proton { /// A simple thread safe set with read/write lock. template > class ThreadSafeSet { public: ThreadSafeSet() = default; void insert(const Key &key) { std::unique_lock lock(mutex); set.insert(key); } bool contain(const Key &key) { std::shared_lock lock(mutex); auto it = set.find(key); if (it == set.end()) return false; return true; } bool erase(const Key &key) { std::unique_lock lock(mutex); return set.erase(key) > 0; } void clear() { std::unique_lock lock(mutex); set.clear(); } private: Container set; std::shared_mutex mutex; }; } // namespace proton #endif // PROTON_UTILITY_MAP_H_