| 60 | } |
| 61 | |
| 62 | void Thread::Stop(bool waitTillStopped) |
| 63 | { |
| 64 | // We also just signal the thread and ask it to stop. |
| 65 | // We don't currently offer a "force thread to stop" method as that's |
| 66 | // generally not a very safe thing to do. If you feel you need it, add a "ForceStop" method. |
| 67 | m_QuitNow = true ; |
| 68 | |
| 69 | // If the thread was never started or is already stopped we're done. |
| 70 | if (!m_Started || IsStopped()) |
| 71 | { |
| 72 | return ; |
| 73 | } |
| 74 | |
| 75 | int maxTries = 1000 ; |
| 76 | |
| 77 | // If we've been asked to wait for the thread to quit then pause for a moment while it terminates. |
| 78 | while (waitTillStopped && !IsStopped() && maxTries > 0) |
| 79 | { |
| 80 | sml::Sleep(0, 10) ; |
| 81 | maxTries-- ; |
| 82 | } |
| 83 | |
| 84 | if (maxTries <= 0) |
| 85 | { |
| 86 | sml::PrintDebug("Timed out waiting for thread to stop") ; |
| 87 | } |
| 88 | } |
| 89 |
no test coverage detected