/src/muduo/muduo/base/CurrentThread.h
Line | Count | Source |
1 | | // Use of this source code is governed by a BSD-style license |
2 | | // that can be found in the License file. |
3 | | // |
4 | | // Author: Shuo Chen (chenshuo at chenshuo dot com) |
5 | | |
6 | | #ifndef MUDUO_BASE_CURRENTTHREAD_H |
7 | | #define MUDUO_BASE_CURRENTTHREAD_H |
8 | | |
9 | | #include "muduo/base/Types.h" |
10 | | |
11 | | namespace muduo |
12 | | { |
13 | | namespace CurrentThread |
14 | | { |
15 | | // internal |
16 | | extern __thread int t_cachedTid; |
17 | | extern __thread char t_tidString[32]; |
18 | | extern __thread int t_tidStringLength; |
19 | | extern __thread const char* t_threadName; |
20 | | void cacheTid(); |
21 | | |
22 | | inline int tid() |
23 | 2 | { |
24 | 2 | if (__builtin_expect(t_cachedTid == 0, 0)) |
25 | 2 | { |
26 | 2 | cacheTid(); |
27 | 2 | } |
28 | 2 | return t_cachedTid; |
29 | 2 | } |
30 | | |
31 | | inline const char* tidString() // for logging |
32 | 0 | { |
33 | 0 | return t_tidString; |
34 | 0 | } |
35 | | |
36 | | inline int tidStringLength() // for logging |
37 | 0 | { |
38 | 0 | return t_tidStringLength; |
39 | 0 | } |
40 | | |
41 | | inline const char* name() |
42 | 0 | { |
43 | 0 | return t_threadName; |
44 | 0 | } |
45 | | |
46 | | bool isMainThread(); |
47 | | |
48 | | void sleepUsec(int64_t usec); // for testing |
49 | | |
50 | | string stackTrace(bool demangle); |
51 | | } // namespace CurrentThread |
52 | | } // namespace muduo |
53 | | |
54 | | #endif // MUDUO_BASE_CURRENTTHREAD_H |