block_queue: use class mutex to protect size() getter

detected with TSAN
This commit is contained in:
Andre Puschmann 2021-06-07 11:51:54 +02:00
parent fb4dd3ba7b
commit 626f24c9f9
1 changed files with 8 additions and 1 deletions

View File

@ -121,7 +121,14 @@ public:
const myobj& front() const { return q.front(); }
size_t size() { return q.size(); }
size_t size()
{
size_t len = 0;
pthread_mutex_lock(&mutex);
len = q.size();
pthread_mutex_unlock(&mutex);
return len;
}
private:
bool pop_(myobj* value, bool block)