MCPcopy Create free account
hub / github.com/Kitware/CMake / testAsyncShutdown

Function testAsyncShutdown

Tests/CMakeLib/testUVRAII.cxx:17–49  ·  view source on GitHub ↗

A common pattern is to use an async signal to shutdown the server.

Source from the content-addressed store, hash-verified

15
16// A common pattern is to use an async signal to shutdown the server.
17static bool testAsyncShutdown()
18{
19 uv_loop_t Loop;
20 auto err = uv_loop_init(&Loop);
21 if (err != 0) {
22 std::cerr << "Could not init loop" << std::endl;
23 return false;
24 }
25
26 {
27 cm::uv_async_ptr signal;
28 signal.init(Loop, &signal_reset_fn, &signal);
29
30 std::thread([&] {
31 std::this_thread::sleep_for(std::chrono::seconds(2));
32 signal.send();
33 }).detach();
34
35 if (uv_run(&Loop, UV_RUN_DEFAULT) != 0) {
36 std::cerr << "Unclean exit state in testAsyncDtor" << std::endl;
37 return false;
38 }
39
40 if (signal) {
41 std::cerr << "Loop exited with signal not being cleaned up" << std::endl;
42 return false;
43 }
44 }
45
46 uv_loop_close(&Loop);
47
48 return true;
49}
50
51static void signal_fn(uv_async_t*)
52{

Callers 1

testUVRAIIFunction · 0.85

Calls 5

uv_loop_closeFunction · 0.85
uv_loop_initFunction · 0.50
uv_runFunction · 0.50
initMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…