X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5fd8cc8409d0efadc07dfe8d6774ad9ff477663d..5987a5357ccfd818d540a7aa58eb498a1be07aa1:/tprintf.h diff --git a/tprintf.h b/tprintf.h index 6a0cb2a..c61626a 100644 --- a/tprintf.h +++ b/tprintf.h @@ -1,27 +1,27 @@ -#ifndef TPRINTF_H -#define TPRINTF_H +#ifndef tprintf_h +#define tprintf_h #include #include -#include "mutex.h" -#include #include #include +#include "lock.h" extern mutex cerr_mutex; -extern std::map thread_name_map; +extern std::map thread_name_map; extern int next_thread_num; extern std::map 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::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