| 115 | } |
| 116 | |
| 117 | void ThreadableUnit::join(int killAfterMillis) |
| 118 | { |
| 119 | // wait until it is safe to terminate |
| 120 | int count = 0; |
| 121 | while ((getState() == Processing) && |
| 122 | ((count < killAfterMillis) || (killAfterMillis < 0))) |
| 123 | { |
| 124 | Sleep(32); |
| 125 | count += 32; |
| 126 | } |
| 127 | |
| 128 | if (getState() == ProcessingIdle || |
| 129 | killAfterMillis > -1) |
| 130 | { |
| 131 | _mutex.lock(); |
| 132 | if (_thread) |
| 133 | { |
| 134 | TerminateThread(_thread, 0); |
| 135 | CloseHandle(_thread); |
| 136 | } |
| 137 | _thread = NULL; |
| 138 | _state = Complete; |
| 139 | _mutex.unlock(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | ThreadableUnit::State ThreadableUnit::getState() |
| 144 | { |