| 157 | } |
| 158 | |
| 159 | void Thread::threadEntryBase() { |
| 160 | pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr); |
| 161 | pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr); |
| 162 | #ifdef HAS_NP_FUNCTIONS |
| 163 | pthread_setname_np(_thread, _name.c_str()); |
| 164 | #else |
| 165 | prctl(PR_SET_NAME, _name.c_str(), 0, 0, 0); |
| 166 | #endif |
| 167 | try { |
| 168 | for (;;) { |
| 169 | switch (_state) { |
| 170 | case State::Starting: |
| 171 | _state = State::Started; |
| 172 | break; |
| 173 | case State::Started: |
| 174 | if (!_threadExecuteFunction()) { |
| 175 | _state = State::Stopping; |
| 176 | } |
| 177 | break; |
| 178 | case State::Pausing: |
| 179 | _state = State::Paused; |
| 180 | break; |
| 181 | case State::Paused: |
| 182 | // Do nothing here, just wait |
| 183 | std::this_thread::sleep_for(std::chrono::milliseconds(150)); |
| 184 | break; |
| 185 | case State::Stopping: |
| 186 | _state = State::Stopped; |
| 187 | break; |
| 188 | case State::Stopped: |
| 189 | return; |
| 190 | default: |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | } catch (...) { |
| 195 | SI_LOG_ERROR("%s: Catched an exception", _name.c_str()); |
| 196 | _state = State::Stopped; |
| 197 | throw; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | } // namespace base |
no outgoing calls
no test coverage detected