提交 92b51a7f authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

DepLibUV: code cleanup

上级 1cb97030
......@@ -16,6 +16,7 @@ public:
private:
static uv_loop_t* loop;
static uint32_t maxTimeCounter;
static uint32_t timeUpdateCounter;
};
......@@ -27,4 +28,17 @@ uv_loop_t* DepLibUV::GetLoop()
return DepLibUV::loop;
}
inline
uint64_t DepLibUV::GetTime()
{
// Update the libuv's concept of “now” every maxTimeCounter usages.
if (++DepLibUV::timeUpdateCounter == DepLibUV::maxTimeCounter)
{
DepLibUV::timeUpdateCounter = 0;
uv_update_time(DepLibUV::loop);
}
return uv_now(DepLibUV::loop);
}
#endif
......@@ -8,8 +8,8 @@
/* Static variables. */
uv_loop_t* DepLibUV::loop = nullptr;
uint32_t DepLibUV::maxTimeCounter = 16384;
uint32_t DepLibUV::timeUpdateCounter = 0;
static uint64_t LAST_NOW = 0;
/* Static methods. */
......@@ -23,8 +23,6 @@ void DepLibUV::ClassInit()
err = uv_loop_init(DepLibUV::loop);
if (err)
MS_ABORT("libuv initialization failed");
LAST_NOW = uv_now(DepLibUV::loop);
}
void DepLibUV::ClassDestroy()
......@@ -56,25 +54,3 @@ void DepLibUV::RunLoop()
uv_run(DepLibUV::loop, UV_RUN_DEFAULT);
}
// TODO: Move to inline in the .h file.
uint64_t DepLibUV::GetTime()
{
static uint32_t maxTimeCounter = 32768;
// TODO: Remove.
if (DepLibUV::timeUpdateCounter == 0)
{
MS_DEBUG_DEV("now - LAST_NOW: %" PRIu64 "ms", uv_now(DepLibUV::loop) - LAST_NOW);
}
// Update the libuv's concept of “now” every N usages.
if (++DepLibUV::timeUpdateCounter == maxTimeCounter)
{
LAST_NOW = uv_now(DepLibUV::loop);
DepLibUV::timeUpdateCounter = 0;
uv_update_time(DepLibUV::loop);
}
return uv_now(DepLibUV::loop);
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论