add function get_current_time_us and get_current_time_ms

pull/5/head
yuqing 2015-10-26 17:07:43 +08:00
parent 46e191925e
commit cb81992905
3 changed files with 26 additions and 1 deletions

View File

@ -1,7 +1,8 @@
Version 1.23 2015-10-16
Version 1.23 2015-10-26
* sched_thread.c: task can execute in a new thread
* sched_thread.c: support delay tasks
* add function get_current_time_us and get_current_time_ms
Version 1.22 2015-10-10
* export php function: fastcommon_get_first_local_ip

View File

@ -2251,3 +2251,19 @@ bool is_private_ip(const char* ip)
return false;
}
int64_t get_current_time_us()
{
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
{
logError("file: "__FILE__", line: %d, " \
"call gettimeofday fail, " \
"errno=%d, error info: %s", \
__LINE__, errno, STRERROR(errno));
return errno != 0 ? errno : EPERM;
}
return ((int64_t)tv.tv_sec * 1000 * 1000 + (int64_t)tv.tv_usec);
}

View File

@ -520,6 +520,14 @@ double get_line_distance_km(const double lat1, const double lon1,
*/
bool is_private_ip(const char* ip);
/** get current time in us
* return: current time
*/
int64_t get_current_time_us();
#define get_current_time_ms() (get_current_time_us() / 1000)
#ifdef __cplusplus
}
#endif