| 99 | } |
| 100 | |
| 101 | bool IOThread::isTerminated(int waitMs) { |
| 102 | |
| 103 | if (terminated.load()) { |
| 104 | return true; |
| 105 | } |
| 106 | else if (waitMs == 0) { |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | //this is a stupid busy plus sleep loop |
| 111 | int nbCyclesToWait; |
| 112 | |
| 113 | if (waitMs < 0) { |
| 114 | nbCyclesToWait = std::numeric_limits<int>::max(); |
| 115 | } |
| 116 | else { |
| 117 | nbCyclesToWait = (waitMs / SPIN_WAIT_SLEEP_MS) + 1; |
| 118 | } |
| 119 | |
| 120 | for ( int i = 0; i < nbCyclesToWait; i++) { |
| 121 | |
| 122 | std::this_thread::sleep_for(std::chrono::milliseconds(SPIN_WAIT_SLEEP_MS)); |
| 123 | |
| 124 | if (terminated.load()) { |
| 125 | return true; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | std::cout << "ERROR: thread '" << typeid(*this).name() << "' has not terminated in time ! (> " << waitMs << " ms)" << std::endl << std::flush; |
| 130 | |
| 131 | return terminated.load(); |
| 132 | } |
no test coverage detected