11 extern mutex cerr_mutex;
12 extern std::map<pthread_t, int> thread_name_map;
13 extern int next_thread_num;
14 extern std::map<void *, int> instance_name_map;
15 extern int next_instance_num;
16 extern char tprintf_thread_prefix;
18 #define LOG_PREFIX { \
19 cerr_mutex.acquire(); \
20 pthread_t self = pthread_self(); \
21 int tid = thread_name_map[self]; \
23 tid = thread_name_map[self] = ++next_thread_num; \
24 std::cerr << std::left << std::setw(9) << utime() << " "; \
25 std::cerr << tprintf_thread_prefix << std::left << std::setw(2) << tid; \
26 std::cerr << " " << std::setw(24) << __FILE__ << " " << std::setw(18) << __func__; \
28 #define LOG_THIS_POINTER { \
29 int self = instance_name_map[this]; \
31 self = instance_name_map[this] = ++next_instance_num; \
32 std::cerr << "#" << std::setw(2) << self; \
34 #define LOG_SUFFIX { \
35 cerr_mutex.release(); \
38 #define LOG_NONMEMBER(x) { \
40 std::cerr << x << std::endl; \
46 std::cerr << x << std::endl; \
49 #define JOIN(from,to,sep) ({ \
51 for(typeof(from) i=from;i!=to;i++) \
55 #define LOG_FUNC_ENTER { \
58 std::cerr << "lid=" << lid; \
59 std::cerr << std::endl; \
62 #define LOG_FUNC_ENTER_SERVER { \
65 std::cerr << "lid=" << lid; \
66 std::cerr << " client=" << id << "," << xid; \
67 std::cerr << std::endl; \
70 #define LOG_FUNC_EXIT { \
73 std::cerr << "return" << lid; \
74 std::cerr << std::endl; \
78 #define tprintf(args...) { \
79 int len = snprintf(NULL, 0, args); \
82 snprintf(buf, len+1, args); \
83 if (buf[len-1]=='\n') \