Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions base/htime.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ unsigned int gettick() {
#endif
}

#ifndef OS_SOLARIS
unsigned long long gethrtime() {
unsigned long long gethrtime_usec() {
#ifdef OS_WIN
static LONGLONG s_freq = 0;
if (s_freq == 0) {
Expand All @@ -56,6 +55,8 @@ unsigned long long gethrtime() {
return (unsigned long long)(count.QuadPart / (double)s_freq * 1000000);
}
return 0;
#elif defined(OS_SOLARIS)
return gethrtime() / 1000;
#elif HAVE_CLOCK_GETTIME
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
Expand All @@ -66,7 +67,6 @@ unsigned long long gethrtime() {
return tv.tv_sec*(unsigned long long)1000000 + tv.tv_usec;
#endif
}
#endif

datetime_t datetime_now() {
datetime_t dt;
Expand Down
5 changes: 1 addition & 4 deletions base/htime.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ static inline unsigned long long timestamp_ms() {
void msleep(unsigned int ms);
// ms
unsigned int gettick();

#ifndef OS_SOLARIS // Solaris has built-in gethrtime().
// us
unsigned long long gethrtime();
#endif
unsigned long long gethrtime_usec();

datetime_t datetime_now();
time_t datetime_mktime(datetime_t* dt);
Expand Down
2 changes: 1 addition & 1 deletion docs/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- datetime_fmt
- gmtime_fmt
- gettick
- gethrtime
- gethrtime_usec
- sleep
- msleep
- usleep
Expand Down
6 changes: 3 additions & 3 deletions event/hloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static void hloop_init(hloop_t* loop) {
hmutex_init(&loop->custom_events_mutex);
// NOTE: init start_time here, because htimer_add use it.
loop->start_ms = timestamp_ms();
loop->start_hrtime = loop->cur_hrtime = gethrtime();
loop->start_hrtime = loop->cur_hrtime = gethrtime_usec();
}

static void hloop_cleanup(hloop_t* loop) {
Expand Down Expand Up @@ -268,7 +268,7 @@ int hloop_run(hloop_t* loop) {
}
}
loop->status = HLOOP_STATUS_STOP;
loop->end_hrtime = gethrtime();
loop->end_hrtime = gethrtime_usec();
if (loop->flags & HLOOP_FLAG_AUTO_FREE) {
hloop_cleanup(loop);
SAFE_FREE(loop);
Expand Down Expand Up @@ -296,7 +296,7 @@ int hloop_resume(hloop_t* loop) {
}

void hloop_update_time(hloop_t* loop) {
loop->cur_hrtime = gethrtime();
loop->cur_hrtime = gethrtime_usec();
if (ABS((int64_t)hloop_now(loop) - (int64_t)time(NULL)) > 1) {
// systemtime changed, we adjust start_ms
loop->start_ms = timestamp_ms() - (loop->cur_hrtime - loop->start_hrtime) / 1000;
Expand Down
4 changes: 2 additions & 2 deletions protocol/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int ping(const char* host, int cnt) {
icmp_req->icmp_seq = ++seq;
icmp_req->icmp_cksum = 0;
icmp_req->icmp_cksum = checksum((uint8_t*)icmp_req, sendbytes);
start_hrtime = gethrtime();
start_hrtime = gethrtime_usec();
addrlen = sockaddrlen(&peeraddr);
int nsend = sendto(sockfd, sendbuf, sendbytes, 0, &peeraddr.sa, addrlen);
if (nsend < 0) {
Expand All @@ -82,7 +82,7 @@ int ping(const char* host, int cnt) {
continue;
}
++recv_cnt;
end_hrtime = gethrtime();
end_hrtime = gethrtime_usec();
// check valid
bool valid = false;
int iphdr_len = ipheader->ihl * 4;
Expand Down