| 31 | } |
| 32 | |
| 33 | TPControl* ThreadPoolBase::thread_create_ex(thread_entry start, void* arg, bool joinable) |
| 34 | { |
| 35 | if (m_capacity == 0 || __should_bypass_threadpool()) { |
| 36 | auto th = photon::thread_create(start, arg, (uint64_t)m_reserved, |
| 37 | sizeof(TPControl)); |
| 38 | auto pCtrl = photon::thread_reserved_space<TPControl>(th); |
| 39 | pCtrl->th = th; |
| 40 | /* Actually unused in `bypass_threadpool` condition |
| 41 | because all threadcreate work are forwarding to |
| 42 | `photon::thread_create` |
| 43 | |
| 44 | // pCtrl->joinable = joinable; |
| 45 | // pCtrl->start = start; |
| 46 | // pCtrl->arg = arg; |
| 47 | */ |
| 48 | if (joinable) { |
| 49 | photon::thread_enable_join(th); |
| 50 | } |
| 51 | return pCtrl; |
| 52 | } |
| 53 | auto pCtrl = B::get(); |
| 54 | { |
| 55 | SCOPED_LOCK(pCtrl->m_mtx); |
| 56 | pCtrl->joinable = joinable; |
| 57 | pCtrl->joining = false; |
| 58 | pCtrl->start = start; |
| 59 | pCtrl->arg = arg; |
| 60 | pCtrl->cvar.notify_one(); |
| 61 | } |
| 62 | return pCtrl; |
| 63 | } |
| 64 | bool ThreadPoolBase::wait_for_work(TPControl &ctrl) |
| 65 | { |
| 66 | SCOPED_LOCK(ctrl.m_mtx); |