添加微秒获取接口

This commit is contained in:
wuxf 2023-02-24 16:55:46 +08:00 committed by ruanshudong
parent 54f356bbf7
commit 83d6195935
2 changed files with 17 additions and 0 deletions

View File

@ -28,6 +28,7 @@ namespace tars
{
#define TNOW TC_TimeProvider::getInstance()->getNow()
#define TNOWMS TC_TimeProvider::getInstance()->getNowMs()
#define TNOWUS TC_TimeProvider::getInstance()->getNowUs()
/////////////////////////////////////////////////
/**
@ -95,6 +96,14 @@ public:
*/
uint64_t getNowMs();
/**
* @brief us时间.
*
* @para timeval
* @return void
*/
uint64_t getNowUs();
protected:
static TC_TimeProvider *g_tp;

View File

@ -114,6 +114,14 @@ uint64_t TC_TimeProvider::getNowMs()
return tv.tv_sec * (int64_t)1000 + tv.tv_usec / 1000;
}
uint64_t TC_TimeProvider::getNowUs()
{
struct timeval tv;
getNow(&tv);
return tv.tv_sec * (int64_t)1000000 + tv.tv_usec;
}
void TC_TimeProvider::run()
{
memset(_tsc, 0x00, sizeof(_tsc));