summaryrefslogtreecommitdiff
path: root/src/message/thread_safe_queue.cpp
blob: 092a2ac2d307fe80955aee0ad0aa24e5cc60335f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "thread_safe_queue.hpp"

namespace smtp::message
{
    void ThreadSafeQueue::Push( Message const &message)
    {
        std::lock_guard<std::mutex> lock{mMutex};
        mMessageQueue.push( message );
        mCondition.notify_one();
    }

    std::shared_ptr<Message> ThreadSafeQueue::WaitAndPop()
    {
        std::unique_lock<std::mutex> lock{mMutex};
        mCondition.wait(lock, [this](){return !mMessageQueue.empty();});
        auto result = std::make_shared<Message>(mMessageQueue.front());
        mMessageQueue.pop();
        return result;
    }

}