Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot convert ‘Message*’ to ‘rigtorp::mpmc::Slot<Message>*’ #30

Closed
mewais opened this issue Jul 30, 2021 · 2 comments
Closed

Comments

@mewais
Copy link

mewais commented Jul 30, 2021

Hi, I am trying to use MPMCQueue with a custom allocator. But I am getting the two following errors:

/Path/To/Project/Debug/external/include/rigtorp/MPMCQueue.h:129:33: error: cannot convert ‘Message*’ to ‘rigtorp::mpmc::Slot<Message>*’ in assignment
  129 |     slots_ = allocator_.allocate(capacity_ + 1);
/Path/To/Project/Debug/external/include/rigtorp/MPMCQueue.h:134:29: error: cannot convert ‘rigtorp::mpmc::Slot<Message>*’ to ‘CommMemoryAllocator<Message>::pointer’ {aka ‘Message*’}
  134 |       allocator_.deallocate(slots_, capacity_ + 1);

This is how I define the allocator and pass it to MPMCQueue:

template <typename T>
class CommMemoryAllocator
{
    public:
        typedef size_t size_type;
        typedef ptrdiff_t difference_type;
        typedef T* pointer;
        typedef const T* const_pointer;
        typedef T& reference;
        typedef const T& const_reference;
        typedef T value_type;

        T* allocate(size_type num, const void* hint = nullptr);

        void deallocate(pointer ptr, size_type num);
};

template <typename T>
using comm_mqueue = rigtorp::MPMCQueue<T, CommMemoryAllocator<T>>;

Then inside one of my classes I actually use it like so:

comm_mqueue<Message> downward_queue{20};

I don't actually use the queues yet (so no pushing or popping), I am getting these errors directly from this simple use.

Is there something I am missing or is this a bug?I am using Linux, gcc/g++ 11.1.0, and this is being compiled as C++17.

@mewais
Copy link
Author

mewais commented Jul 30, 2021

For completeness, the data structure Message is as follows:

class Message
{
    public:
        uint32_t destination;
        uint32_t source;
        uint32_t process;
        uint32_t tag;
        MessageType type;				// This is just an enum
        MessageDirection direction;		// an enum too
        uint32_t size;
        void* data;

        // constructor
        Message(uint32_t host, uint32_t process, uint32_t tag, MessageType type, MessageDirection direction, 
                uint32_t size, void* data);
        // constructor
        Message(uint32_t source, uint32_t process, uint32_t tag, MessageType type);
};

@rigtorp
Copy link
Owner

rigtorp commented Aug 1, 2021 via email

@mewais mewais closed this as completed Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants