PracticeDev/study_clang/Mimic/message_queue/CMessageQueue.h

29 lines
757 B
C
Raw Permalink Normal View History

2022-12-20 17:31:11 +08:00
/*************************************************************************
> File Name: CMessageQueue.h
> Author: SongTL
> Mail: songtianlun@comleader.com.cn
> Created Time: 20200721 164637
************************************************************************/
#ifndef CMESSAGEQUEUE_H
#define CMESSAGEQUEUE_H
template<class Type>
class ConcurrentQueue
{
ConcurrentQueue& operator = (const ConcurrentQueue&) = delete;
ConcurrentQueue(const ConcurrentQueue& other) = delete;
public:
ConcurrentQueue() : _queue(), _mutex(), _condition() {}
virtual ~ConcurrentQueue() {}
void Push(Type record)
{
std::lock_guard <std::mutex> lock(_mutex);
_queue.push(record);
_condition.notify_one();
}
}
#endif