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

DepLibUV: code cleanup

上级 1cb97030
...@@ -16,6 +16,7 @@ public: ...@@ -16,6 +16,7 @@ public:
private: private:
static uv_loop_t* loop; static uv_loop_t* loop;
static uint32_t maxTimeCounter;
static uint32_t timeUpdateCounter; static uint32_t timeUpdateCounter;
}; };
...@@ -27,4 +28,17 @@ uv_loop_t* DepLibUV::GetLoop() ...@@ -27,4 +28,17 @@ uv_loop_t* DepLibUV::GetLoop()
return DepLibUV::loop; 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 #endif
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
/* Static variables. */ /* Static variables. */
uv_loop_t* DepLibUV::loop = nullptr; uv_loop_t* DepLibUV::loop = nullptr;
uint32_t DepLibUV::maxTimeCounter = 16384;
uint32_t DepLibUV::timeUpdateCounter = 0; uint32_t DepLibUV::timeUpdateCounter = 0;
static uint64_t LAST_NOW = 0;
/* Static methods. */ /* Static methods. */
...@@ -23,8 +23,6 @@ void DepLibUV::ClassInit() ...@@ -23,8 +23,6 @@ void DepLibUV::ClassInit()
err = uv_loop_init(DepLibUV::loop); err = uv_loop_init(DepLibUV::loop);
if (err) if (err)
MS_ABORT("libuv initialization failed"); MS_ABORT("libuv initialization failed");
LAST_NOW = uv_now(DepLibUV::loop);
} }
void DepLibUV::ClassDestroy() void DepLibUV::ClassDestroy()
...@@ -56,25 +54,3 @@ void DepLibUV::RunLoop() ...@@ -56,25 +54,3 @@ void DepLibUV::RunLoop()
uv_run(DepLibUV::loop, UV_RUN_DEFAULT); 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 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论