From 3489b03e77ed8d8e7aca2016ca267ba35ab53016 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 4 Sep 2015 16:19:35 +0200 Subject: add structures for message spools and pools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsclient/inbound.h | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'src/libmdsclient') diff --git a/src/libmdsclient/inbound.h b/src/libmdsclient/inbound.h index 87b96f4..74f0664 100644 --- a/src/libmdsclient/inbound.h +++ b/src/libmdsclient/inbound.h @@ -22,6 +22,7 @@ #include +#include @@ -92,6 +93,100 @@ typedef struct libmds_message } libmds_message_t; +/** + * Queue of spooled messages + */ +typedef struct libmds_mspool +{ + /** + * Array of messages + */ + libmds_message_t** messages; + + /** + * The number of elements the current + * allocation of `messages` can hold + */ + size_t size; + + /** + * Push end + */ + size_t head; + + /** + * Poll end + */ + size_t tail; + + /** + * The total size of all spooled messages + */ + size_t spooled_bytes; + + /** + * Do not spool additional messages if + * `spooled_bytes` is equal to or exceeds + * to value + */ + size_t spool_limit_bytes; + + /** + * Do not spool more than this amount + * of messages + */ + size_t spool_limit_messages; + + /* POSIX semaphores are lighter weight than XSI semaphores, so we use POSIX here. */ + + /** + * Binary semaphore used to lock the spool whilst + * manipulating it + */ + sem_t lock; + + /** + * Seamphore used to signal addition of messages, + * each time a message is spooled, this semaphore + * in increased, the polling thread decreases the + * the semaphore before despooling a message, + * causing it to block when the spool is empty + */ + sem_t semaphore; + +} libmds_mspool_t; + + +/** + * Message pool for reusable message allocations + */ +typedef struct libmds_mpool +{ + /** + * Array of messages + */ + libmds_message_t** messages; + + /** + * The number of elements the current + * allocation of 'messages` can hold + */ + size_t size; + + /** + * The tip of the stack + */ + size_t tip; + + /** + * Binary semaphore used to lock the pool + * whilst manipulating it + */ + sem_t lock; + +} libmds_mpool_t; + + /** * Initialise a message slot so that it can -- cgit v1.2.3-70-g09d2