-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrentThread.cc
More file actions
34 lines (28 loc) · 886 Bytes
/
CurrentThread.cc
File metadata and controls
34 lines (28 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// Created by satellite on 2023-11-14.
//
#include <cstdio>
#include <csignal>
#include <ctime>
#include "CurrentThread.h"
#include "unistd.h"
#include "sys/syscall.h"
#include "Timestamp.h"
namespace CurrentThread {
__thread int t_cachedTid;
__thread char t_tidString[32];
__thread int t_tidStringLength = 6;
__thread const char * t_threadName = "unknown";
void cacheTid() {
if(t_cachedTid == 0) {
t_cachedTid = static_cast<pid_t>(syscall(SYS_gettid));
t_tidStringLength = snprintf(t_tidString,sizeof t_tidString,"%5d ",t_cachedTid);
}
}
void sleepUsec(int64_t usec) {
struct timespec ts = {0,0};
ts.tv_sec = static_cast<time_t>(usec/Timestamp::kMicroSecondsPerSecond);
ts.tv_nsec = static_cast<long>(usec % Timestamp::kMicroSecondsPerSecond);
::nanosleep(&ts , NULL);
}
}