diff options
Diffstat (limited to 'tpool/tpool_structs.h')
-rw-r--r-- | tpool/tpool_structs.h | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/tpool/tpool_structs.h b/tpool/tpool_structs.h index 7b0fb857695..08c17540f69 100644 --- a/tpool/tpool_structs.h +++ b/tpool/tpool_structs.h @@ -94,6 +94,10 @@ public: return ret; } + std::mutex& mutex() + { + return m_mtx; + } void put(T *ele) { @@ -112,19 +116,37 @@ public: return ele >= &m_base[0] && ele <= &m_base[m_base.size() -1]; } - /* Wait until cache is full.*/ - void wait() + + TPOOL_SUPPRESS_TSAN size_t size() + { + return m_cache.size(); + } + + /** Wait until cache is full + @param[in] lk - lock for the cache mutex + (which can be obtained with mutex()) */ + void wait(std::unique_lock<std::mutex> &lk) { - std::unique_lock<std::mutex> lk(m_mtx); m_waiters++; - while(!is_full()) + while (!is_full()) m_cv.wait(lk); m_waiters--; } + + /* Wait until cache is full.*/ + void wait() + { + std::unique_lock<std::mutex> lk(m_mtx); + wait(lk); + } - TPOOL_SUPPRESS_TSAN size_t size() + void resize(size_t count) { - return m_cache.size(); + assert(is_full()); + m_base.resize(count); + m_cache.resize(count); + for (size_t i = 0; i < count; i++) + m_cache[i] = &m_base[i]; } }; |