-#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__; \
}
std::cerr << "#" << std::setw(2) << self; \
}
#define LOG_SUFFIX { \
- cerr_mutex.release(); \
+ cerr_mutex.unlock(); \
}
#define LOG_NONMEMBER(x) { \
}
#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(); \
})
LOG_NONMEMBER(buf); \
}
-uint64_t utime();
-
#endif