diff options
author | Mauro <you@example.com> | 2021-06-30 07:57:22 +0000 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2021-07-06 16:16:04 +0000 |
commit | 08233d44a6cfde878d7e10bca38ae935ed1c8fd5 (patch) | |
tree | 7ecc534d55bdc7e8dd15ecab084720910bcdf4d9 /libtransport/src/io_modules/forwarder/global_id_counter.h | |
parent | 147ba39bed26887f5eba84757e2463ab8e370a9a (diff) |
[HICN-713] Transport Library Major Refactoring 2
Co-authored-by: Luca Muscariello <muscariello@ieee.org>
Co-authored-by: Michele Papalini <micpapal@cisco.com>
Co-authored-by: Olivier Roques <oroques+fdio@cisco.com>
Co-authored-by: Giulio Grassi <gigrassi@cisco.com>
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Change-Id: I5b2c667bad66feb45abdb5effe22ed0f6c85d1c2
Diffstat (limited to 'libtransport/src/io_modules/forwarder/global_id_counter.h')
-rw-r--r-- | libtransport/src/io_modules/forwarder/global_id_counter.h | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/libtransport/src/io_modules/forwarder/global_id_counter.h b/libtransport/src/io_modules/forwarder/global_id_counter.h index fe8d76730..0a67b76d5 100644 --- a/libtransport/src/io_modules/forwarder/global_id_counter.h +++ b/libtransport/src/io_modules/forwarder/global_id_counter.h @@ -15,6 +15,8 @@ #pragma once +#include <hicn/transport/utils/singleton.h> + #include <atomic> #include <mutex> @@ -23,32 +25,15 @@ namespace transport { namespace core { template <typename T = uint64_t> -class GlobalCounter { +class GlobalCounter : public utils::Singleton<GlobalCounter<T>> { public: - static GlobalCounter& getInstance() { - std::lock_guard<std::mutex> lock(global_mutex_); - - if (!instance_) { - instance_.reset(new GlobalCounter()); - } - - return *instance_; - } - + friend class utils::Singleton<GlobalCounter>; T getNext() { return counter_++; } private: GlobalCounter() : counter_(0) {} - static std::unique_ptr<GlobalCounter<T>> instance_; - static std::mutex global_mutex_; std::atomic<T> counter_; }; -template <typename T> -std::unique_ptr<GlobalCounter<T>> GlobalCounter<T>::instance_ = nullptr; - -template <typename T> -std::mutex GlobalCounter<T>::global_mutex_; - } // namespace core } // namespace transport
\ No newline at end of file |