mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-23 00:48:55 +08:00
cmUVHandlePtr: Add uv_idle_ptr
Wrap a `uv_idle_t` handle.
This commit is contained in:
@@ -254,12 +254,20 @@ int uv_tty_ptr::init(uv_loop_t& loop, int fd, int readable, void* data)
|
||||
}
|
||||
#endif
|
||||
|
||||
int uv_idle_ptr::init(uv_loop_t& loop, void* data)
|
||||
{
|
||||
this->allocate(data);
|
||||
return uv_idle_init(&loop, *this);
|
||||
}
|
||||
|
||||
template class uv_handle_ptr_base_<uv_handle_t>;
|
||||
|
||||
#define UV_HANDLE_PTR_INSTANTIATE_EXPLICIT(NAME) \
|
||||
template class uv_handle_ptr_base_<uv_##NAME##_t>; \
|
||||
template class uv_handle_ptr_<uv_##NAME##_t>;
|
||||
|
||||
UV_HANDLE_PTR_INSTANTIATE_EXPLICIT(idle)
|
||||
|
||||
UV_HANDLE_PTR_INSTANTIATE_EXPLICIT(signal)
|
||||
|
||||
UV_HANDLE_PTR_INSTANTIATE_EXPLICIT(pipe)
|
||||
|
@@ -196,6 +196,13 @@ public:
|
||||
void send();
|
||||
};
|
||||
|
||||
struct uv_idle_ptr : public uv_handle_ptr_<uv_idle_t>
|
||||
{
|
||||
CM_INHERIT_CTOR(uv_idle_ptr, uv_handle_ptr_, <uv_idle_t>);
|
||||
|
||||
int init(uv_loop_t& loop, void* data = nullptr);
|
||||
};
|
||||
|
||||
struct uv_signal_ptr : public uv_handle_ptr_<uv_signal_t>
|
||||
{
|
||||
CM_INHERIT_CTOR(uv_signal_ptr, uv_handle_ptr_, <uv_signal_t>);
|
||||
@@ -255,6 +262,8 @@ extern template class uv_handle_ptr_base_<uv_handle_t>;
|
||||
|
||||
UV_HANDLE_PTR_INSTANTIATE_EXTERN(async)
|
||||
|
||||
UV_HANDLE_PTR_INSTANTIATE_EXTERN(idle)
|
||||
|
||||
UV_HANDLE_PTR_INSTANTIATE_EXTERN(signal)
|
||||
|
||||
UV_HANDLE_PTR_INSTANTIATE_EXTERN(pipe)
|
||||
|
@@ -162,6 +162,7 @@ static bool testAllMoves()
|
||||
uv_async_ptr _13;
|
||||
uv_signal_ptr _14;
|
||||
uv_handle_ptr _15;
|
||||
uv_idle_ptr _16;
|
||||
};
|
||||
|
||||
allTypes a;
|
||||
@@ -218,6 +219,30 @@ static bool testLoopDestructor()
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool testIdle()
|
||||
{
|
||||
bool idled = false;
|
||||
|
||||
cm::uv_loop_ptr loop;
|
||||
loop.init();
|
||||
|
||||
cm::uv_idle_ptr idle;
|
||||
idle.init(*loop, &idled);
|
||||
uv_idle_start(idle, [](uv_idle_t* handle) {
|
||||
auto idledPtr = static_cast<bool*>(handle->data);
|
||||
*idledPtr = true;
|
||||
uv_idle_stop(handle);
|
||||
});
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
|
||||
if (!idled) {
|
||||
std::cerr << "uv_idle_ptr did not trigger callback" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int testUVRAII(int, char** const)
|
||||
{
|
||||
if (!testAsyncShutdown()) {
|
||||
@@ -230,5 +255,6 @@ int testUVRAII(int, char** const)
|
||||
passed = testAllMoves() && passed;
|
||||
passed = testLoopReset() && passed;
|
||||
passed = testLoopDestructor() && passed;
|
||||
passed = testIdle() && passed;
|
||||
return passed ? 0 : -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user