| 54 | } |
| 55 | |
| 56 | void StartShutdown() |
| 57 | { |
| 58 | #ifdef WIN32 |
| 59 | std::unique_lock<std::mutex> lk(g_shutdown_mutex); |
| 60 | fRequestShutdown = true; |
| 61 | g_shutdown_cv.notify_one(); |
| 62 | #else |
| 63 | // This must be reentrant and safe for calling in a signal handler, so using a condition variable is not safe. |
| 64 | // Make sure that the token is only written once even if multiple threads call this concurrently or in |
| 65 | // case of a reentrant signal. |
| 66 | if (!fRequestShutdown.exchange(true)) { |
| 67 | // Write an arbitrary byte to the write end of the shutdown pipe. |
| 68 | int res = g_shutdown_w.TokenWrite('x'); |
| 69 | if (res != 0) { |
| 70 | LogPrintf("Sending shutdown token failed\n"); |
| 71 | assert(0); |
| 72 | } |
| 73 | } |
| 74 | #endif |
| 75 | } |
| 76 | |
| 77 | void AbortShutdown() |
| 78 | { |
no test coverage detected