From 1ec41f2171219fac756389b496e3782e5f46985a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20Tomic=CC=8Cevic=CC=81?=
 <dominik.tomicevic@gmail.com>
Date: Tue, 6 Oct 2015 23:15:48 +0200
Subject: [PATCH] implemented a simple asynchronous logging infrastructure

---
 mpsc.cpp              | 42 +++++-------------------------------------
 utils/bash_colors.hpp | 13 +++++++++++++
 2 files changed, 18 insertions(+), 37 deletions(-)
 create mode 100644 utils/bash_colors.hpp

diff --git a/mpsc.cpp b/mpsc.cpp
index ca36c42c5..97e6da9e1 100644
--- a/mpsc.cpp
+++ b/mpsc.cpp
@@ -3,68 +3,36 @@
 #include <thread>
 #include <atomic>
 
-#include "data_structures/queue/mpsc_queue.hpp"
+#include "debug/log.hpp"
 
 static constexpr int N = 1000;
 
-std::atomic<bool> alive { true };
-
 using q_t = lockfree::MpscQueue<std::string>;
 
-void produce(q_t& q)
+void produce()
 {
     std::hash<std::thread::id> hasher;
 
     for(int i = 0; i < N; ++i)
     {
-        auto str = std::to_string(i) + " " +
+        auto str = "Hello number " + std::to_string(i) + " from thread " +
             std::to_string(hasher(std::this_thread::get_id()));
 
-        q.push(std::make_unique<std::string>(str));
-    }
-}
-
-void consume(q_t& q)
-{
-    using namespace std::chrono_literals;
-
-    int i = 0;
-
-    while(true)
-    {
-        auto message = q.pop();
-
-        if(message != nullptr)
-        {
-            std::cerr << (i++) << ": " << *message << std::endl;
-            continue;
-        }
-
-        if(!alive)
-            return;
-
-        std::this_thread::sleep_for(10ms);
+        LOG_DEBUG(str);
     }
 }
 
 int main(void)
 {
     constexpr int THREADS = 256;
-    q_t q;
-
-    auto consumer = std::thread([&q]() { consume(q); });
     
     std::vector<std::thread> threads;
 
     for(int i = 0; i < THREADS; ++i)
-        threads.push_back(std::thread([&q]() { produce(q); }));
+        threads.push_back(std::thread([]() { produce(); }));
 
     for(auto& thread : threads)
         thread.join();
 
-    std::cout << "FINISHED" << std::endl;
-    alive.store(false);
-    consumer.join();
-
     return 0;
 }
diff --git a/utils/bash_colors.hpp b/utils/bash_colors.hpp
new file mode 100644
index 000000000..185cfe784
--- /dev/null
+++ b/utils/bash_colors.hpp
@@ -0,0 +1,13 @@
+#ifndef MEMGRAPH_UTILS_BASH_COLORS_HPP
+#define MEMGRAPH_UTILS_BASH_COLORS_HPP
+
+namespace bash_color
+{
+    auto blue   = "\033[94m";
+    auto green  = "\033[92m";
+    auto yellow = "\033[93m";
+    auto red    = "\033[91m";
+    auto end    = "\033[0m";
+}
+
+#endif