| 84 | } |
| 85 | |
| 86 | void thread_base::finish() { |
| 87 | if (thread_obj != nullptr) { |
| 88 | if ((get_thread_status() == THREAD_STATUS::FINISHED && !thread_obj->joinable()) || |
| 89 | get_thread_status() == THREAD_STATUS::INIT) { |
| 90 | // already finished or uninitialized, nothing to do here |
| 91 | } else { |
| 92 | // signal thread to finish |
| 93 | set_thread_should_finish(); |
| 94 | |
| 95 | // wait a few ms |
| 96 | std::this_thread::sleep_for(100ms); |
| 97 | |
| 98 | // this will block until the thread is finished |
| 99 | if (thread_obj->joinable()) { |
| 100 | thread_obj->join(); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // finally: kill the thread object |
| 105 | thread_obj = nullptr; |
| 106 | } |
| 107 | // else: thread doesn't exist |
| 108 | |
| 109 | set_thread_status(THREAD_STATUS::FINISHED); |
| 110 | } |
| 111 | |
| 112 | void thread_base::set_thread_status(const thread_base::THREAD_STATUS status) { |
| 113 | thread_status = status; |
nothing calls this directly
no outgoing calls
no test coverage detected