/* * ===================================================================================== * * Filename: lock_free_queue.h * * Description: * * Version: 1.0 * Created: 2021年04月21日 14时03分27秒 * Revision: none * Compiler: gcc * * Author: Li Chao (), lichao@aiotlink.com * Organization: * * ===================================================================================== */ #ifndef LOCK_FREE_QUEUE_KQWP70HT #define LOCK_FREE_QUEUE_KQWP70HT #include "shm.h" #include #include using namespace bhome_shm; typedef int64_t Data; const int kQLen = 10; class LockFreeQueue : private boost::lockfree::queue>, boost::lockfree::capacity>, private boost::noncopyable { typedef boost::lockfree::queue>, boost::lockfree::capacity> Queue; public: LockFreeQueue(SharedMemory &shm) : Queue(shm.get_segment_manager()) {} bool Read(Data &d) { return pop(d); } bool Write(Data const &d) { return push(d); } template bool Write(Data const &d, Func onWrite) { if (Write(d)) { onWrite(d); return true; } else { return false; } } }; #endif // end of include guard: LOCK_FREE_QUEUE_KQWP70HT