16 lines
421 B
C++
16 lines
421 B
C++
template <typename T>
|
|
void
|
|
threadsafe_queue<T>::push(T new_value)
|
|
{
|
|
std::shared_ptr<T> new_data(std::make_shared<T>(std::move(new_value)));
|
|
std::unique_ptr<node> p(new node);
|
|
{
|
|
std::lock_guard<std::mutex> tail_lock(tail_mutex);
|
|
tail->data = new_data;
|
|
node* const new_tail = p.get();
|
|
tail->next = std::move(p);
|
|
tail = new_tail;
|
|
}
|
|
data_cond.notify_one();
|
|
}
|