I tried several hours, and this problem almost drives me crazy.
I want create a spsc_queue
over shared memory, and each element in the queue is a mq_item_t
structure below.
typedef struct _mq_item_t{
mq_item_type type;
union
{
struct{
log_level_t level;
char * text;
} log;
struct{
char * control;
size_t control_size;
char * payload;
size_t payload_size;
} error;
struct{
char * channel;
char * control;
size_t control_size;
char * payload;
size_t payload_size;
} data;
};
} mq_item_t;
Then I have following code to create the spsc_queue
.
typedef boost::interprocess::managed_windows_shared_memory native_managed_shared_memory;
typedef boost::interprocess::allocator<mq_item_t, native_managed_shared_memory::segment_manager> shmem_allocator;
typedef boost::lockfree::spsc_queue< mq_item_t, boost::lockfree::allocator<shmem_allocator>> lockfree_queue;
m_segment = new native_managed_shared_memory(create_only, mem_name, SHARED_MEMORY_BYTES, NULL, perm);
shmem_allocator alloc(m_segment->get_segment_manager());
m_segment->find_or_construct<lockfree_queue>("name of the queue")(65535, alloc);
And it results in compilation error. Please what I am doing wrong here?
boost/lockfree/spsc_queue.hpp(609): error C2664: 'boost::lockfree::detail::ringbuffer_base<T>::pop' : cannot convert parameter 3 from 'boost::interprocess::offset_ptr<PointedType,DifferenceType,OffsetType,OffsetAlignment>' to 'mq_item_t *'
1> with
1> [
1> T=mq_item_t
1> ]
1> and
1> [
1> PointedType=mq_item_t,
1> DifferenceType=ptrdiff_t,
1> OffsetType=size_t,
1> OffsetAlignment=0x00
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> boost/lockfree/spsc_queue.hpp(608) : while compiling class template member function 'boost::lockfree::detail::runtime_sized_ringbuffer<T,Alloc>::size_type boost::lockfree::detail::runtime_sized_ringbuffer<T,Alloc>::pop(T *,boost::lockfree::detail::runtime_sized_ringbuffer<T,Alloc>::size_type)'
1> with
1> [
1> T=mq_item_t,
1> Alloc=boost::interprocess::allocator<mq_item_t,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>
1> ]
1> boost/lockfree/spsc_queue.hpp(681) : see reference to class template instantiation 'boost::lockfree::detail::runtime_sized_ringbuffer<T,Alloc>' being compiled
1> with
1> [
1> T=mq_item_t,
1> Alloc=boost::interprocess::allocator<mq_item_t,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>
1> ]
1> boost/interprocess/detail/named_proxy.hpp(213) : see reference to class template instantiation 'boost::lockfree::spsc_queue<T,A0>' being compiled
1> with
1> [
1> T=mq_item_t,
1> A0=boost::lockfree::allocator<shmem_allocator>
1> ]
1> boost/interprocess/detail/named_proxy.hpp(213) : while compiling class template member function 'void boost::interprocess::ipcdetail::CtorArg2<T,P0,P1>::construct_n(void *,size_t,size_t &)'
1> with
1> [
1> T=lockfree_queue,
1> P0=int,
1> P1=boost::interprocess::allocator<mq_item_t,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>> &
1> ]
1> boost/interprocess/detail/named_proxy.hpp(282) : see reference to class template instantiation 'boost::interprocess::ipcdetail::CtorArg2<T,P0,P1>' being compiled
1> with
1> [
1> T=lockfree_queue,
1> P0=int,
1> P1=boost::interprocess::allocator<mq_item_t,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>> &
1> ]
1> ..\common\sink.cpp(26) : see reference to function template instantiation 'T *boost::interprocess::ipcdetail::named_proxy<SegmentManager,T,is_iterator>::operator ()<int,shmem_allocator&>(P0 &&,P1) const' being compiled
1> with
1> [
1> T=lockfree_queue,
1> SegmentManager=boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>,
1> is_iterator=false,
1> P0=int,
1> P1=shmem_allocator &
1> ]