Wait for a thread to complete. When a thread calls TSThreadCreate, it becomes the owner of the thread's mutex. Since only the thread that locked a mutex should be allowed to unlock it (a condition that is enforced for PTHREAD_MUTEX_ERRORCHECK), if the application needs to delete the thread, it must first wait for the thread to complete.
| 160 | // needs to delete the thread, it must first wait for the thread to |
| 161 | // complete. |
| 162 | void |
| 163 | TSThreadWait(TSThread thread) |
| 164 | { |
| 165 | sdk_assert(sdk_sanity_check_iocore_structure(thread) == TS_SUCCESS); |
| 166 | INKThreadInternal *ithread = reinterpret_cast<INKThreadInternal *>(thread); |
| 167 | |
| 168 | ink_mutex_acquire(&ithread->completion.lock); |
| 169 | |
| 170 | if (ithread->completion.done == false) { |
| 171 | ink_cond_wait(&ithread->completion.signal, &ithread->completion.lock); |
| 172 | } |
| 173 | |
| 174 | ink_mutex_release(&ithread->completion.lock); |
| 175 | } |
| 176 | |
| 177 | TSThread |
| 178 | TSThreadInit() |