From ad4f3dcedab29a690c5eedbb08ba1b393917db0b Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期三, 21 四月 2021 17:39:34 +0800 Subject: [PATCH] update go api. --- utest/lock_free_queue.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 57 insertions(+), 0 deletions(-) diff --git a/utest/lock_free_queue.h b/utest/lock_free_queue.h new file mode 100644 index 0000000..968f796 --- /dev/null +++ b/utest/lock_free_queue.h @@ -0,0 +1,57 @@ +/* + * ===================================================================================== + * + * 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 <boost/interprocess/offset_ptr.hpp> +#include <boost/lockfree/queue.hpp> + +using namespace bhome_shm; + +typedef int64_t Data; +const int kQLen = 10; +class LockFreeQueue : private boost::lockfree::queue<Data, + boost::lockfree::allocator<Allocator<Data>>, + boost::lockfree::capacity<kQLen>>, + private boost::noncopyable +{ + typedef boost::lockfree::queue<Data, + boost::lockfree::allocator<Allocator<Data>>, + boost::lockfree::capacity<kQLen>> + 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 <class Func> + 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 -- Gitblit v1.8.0