More renaming
[invirt/third/libt4.git] / tprintf.h
index 6a0cb2a..c61626a 100644 (file)
--- a/tprintf.h
+++ b/tprintf.h
@@ -1,27 +1,27 @@
-#ifndef TPRINTF_H
-#define TPRINTF_H
+#ifndef tprintf_h
+#define tprintf_h
 
 #include <iomanip>
 #include <iostream>
-#include "mutex.h"
-#include <time.h>
 #include <stdio.h>
 #include <map>
+#include "lock.h"
 
 extern mutex cerr_mutex;
-extern std::map<pthread_t, int> thread_name_map;
+extern std::map<std::thread::id, int> thread_name_map;
 extern int next_thread_num;
 extern std::map<void *, int> instance_name_map;
 extern int next_instance_num;
 extern char tprintf_thread_prefix;
 
 #define LOG_PREFIX { \
-    cerr_mutex.acquire(); \
-    pthread_t self = pthread_self(); \
+    cerr_mutex.lock(); \
+    auto self = std::this_thread::get_id(); \
     int tid = thread_name_map[self]; \
     if (tid==0) \
         tid = thread_name_map[self] = ++next_thread_num; \
-    std::cerr << std::left << std::setw(9) << utime() << " "; \
+    auto utime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count() % 1000000000; \
+    std::cerr << std::left << std::setw(9) << utime << " "; \
     std::cerr << tprintf_thread_prefix << std::left << std::setw(2) << tid; \
     std::cerr << " " << std::setw(24) << __FILE__ << " " << std::setw(18) << __func__; \
 }
@@ -32,7 +32,7 @@ extern char tprintf_thread_prefix;
     std::cerr << "#" << std::setw(2) << self; \
 }
 #define LOG_SUFFIX { \
-    cerr_mutex.release(); \
+    cerr_mutex.unlock(); \
 }
 
 #define LOG_NONMEMBER(x) { \
@@ -48,7 +48,7 @@ extern char tprintf_thread_prefix;
 }
 #define JOIN(from,to,sep) ({ \
     ostringstream oss; \
-    for(typeof(from) i=from;i!=to;i++) \
+    for(auto i=from;i!=to;i++) \
         oss << *i << sep; \
     oss.str(); \
 })
@@ -85,6 +85,4 @@ extern char tprintf_thread_prefix;
     LOG_NONMEMBER(buf); \
 }
 
-uint64_t utime();
-
 #endif