version 4.0.7
[ric-plt/e2.git] / RIC-E2-TERMINATION / statCollector.h
index bb4ce5d..3279585 100644 (file)
@@ -33,6 +33,9 @@
 #include <ctime>
 #include <iomanip>
 #include <mdclog/mdclog.h>
+//#include <tbb/concurrent_unordered_map.h>
+
+//using namespace tbb;
 
 typedef struct statResult {
     std::string ranName;
@@ -89,29 +92,44 @@ public:
     StatCollector& operator=(const StatCollector&)= delete;
 
 private:
+    //tbb::concurrent_unordered_map<std::string, int> sentMessages;
     std::unordered_map<std::string, std::atomic<int>> sentMessages;
     std::unordered_map<std::string, std::atomic<int>> recvMessages;
+//    tbb::concurrent_unordered_map<std::string, int> recvMessages;
     std::vector<statResult_t> results;
 
 
-    StatCollector() = default;
+//    StatCollector() = default;
+    StatCollector() {
+        sentMessages.clear();
+        recvMessages.clear();
+    }
     ~StatCollector() = default;
 
 
-    void inline static increment(std::unordered_map<std::string, std::atomic<int>> &map, const std::string &key) {
-        auto found = map.find(key);
-        if (found != map.end()) { //inc
-            map[key].fetch_add(1, std::memory_order_release);
-        } else { //add
-            //sentMessages.emplace(std::make_pair(std::string(key), std::atomic<int>(0)));
-            map.emplace(std::piecewise_construct,
-                                 std::forward_as_tuple(key),
-                                 std::forward_as_tuple(0));
-        }
+    void increment(std::unordered_map<std::string, std::atomic<int>> &map, const std::string &key);
+
+};
 
+void StatCollector::increment(std::unordered_map<std::string, std::atomic<int>> &map, const std::string &key) {
+    if (map.empty()) {
+        map.emplace(std::piecewise_construct,
+                    std::forward_as_tuple(key),
+                    std::forward_as_tuple(1));
+        return;
+    }
+    auto found = map.find(key);
+    if (found != map.end()) { //inc
+        map[key].fetch_add(1, std::memory_order_release);
+        //map[key]++;
+    } else { //add
+        //sentMessages.emplace(std::make_pair(std::string(key), std::atomic<int>(0)));
+        map.emplace(std::piecewise_construct,
+                    std::forward_as_tuple(key),
+                    std::forward_as_tuple(1));
     }
 
-};
+}
 
 
 // must define this to allow StatCollector private variables to be known to compiler linker