Understanding Queues

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
awygle
Posts: 32
Joined: Sun Apr 03, 2016 8:39 pm
Has thanked: 6 times
Been thanked: 4 times

Understanding Queues

Post by awygle »

Hi all,

I have an application with an architecture similar to the Actor model (Wiki link) where a queue of fixed-length buffers ("messages") is processed one at a time by a worker thread. I am trying to understand the best way to do this in ChibiOS (specifically NIL, although I'd consider RT if there were RT-only features that would be very helpful). I am working on the most recent SVN trunk.

I can see a way to do this using a message pool and mailboxes, by calling chPoolAlloc from the thread sending the message and posting the resulting void * to a mailbox which the worker thread pends on, then calling chPoolFree from the worker thread when processing is complete. This seems pretty complicated but would certainly work. However, I also notice a couple other data structures that could be useful. There are queue implementations, formerly in RT but now only in HAL. Are these more appropriate for what I'm trying to do? What about the synchronous message interface? It seems like there are a lot of options but a lack of guidance on their intended use cases.

Appreciate the help!
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Understanding Queues

Post by Giovanni »

Hi,

The best way to do that is exactly MailBoxes + Pools.

Note that now NIL supports both mailboxes and pools, RT4 and NIL2 share a lot of modules in the next generation, the code is in trunk and is basically finalized.

Now pools also support "guarded pools" now, those are pools guarded by a semaphore, you wait if the pool is empty and you try to get an object.

Giovanni
awygle
Posts: 32
Joined: Sun Apr 03, 2016 8:39 pm
Has thanked: 6 times
Been thanked: 4 times

Re: Understanding Queues

Post by awygle »

Thanks for your help, Giovanni, the mailboxes + pools approach is working great :). I am really grateful that you decided to share code between RT and NIL for these things and for binary semaphores, a lot of RTOS writers would not have bothered
Post Reply