aboutsummaryrefslogtreecommitdiffstats
path: root/src/gqueue
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-02-19 00:36:52 +1000
committerinmarket <andrewh@inmarket.com.au>2014-02-19 00:36:52 +1000
commit37966ff16d923bbca53c9464815cb49cbd7fc3be (patch)
treed92db57067ffadd50cadf3ccf70efba3ac16e114 /src/gqueue
parent1e131851d6732e22f055c893face6b473a26f111 (diff)
downloaduGFX-37966ff16d923bbca53c9464815cb49cbd7fc3be.tar.gz
uGFX-37966ff16d923bbca53c9464815cb49cbd7fc3be.tar.bz2
uGFX-37966ff16d923bbca53c9464815cb49cbd7fc3be.zip
Integrate the include files with each module. Simplifies structure of code.
Diffstat (limited to 'src/gqueue')
-rw-r--r--src/gqueue/sys_defs.h264
-rw-r--r--src/gqueue/sys_make.mk (renamed from src/gqueue/gqueue.mk)0
-rw-r--r--src/gqueue/sys_options.h53
-rw-r--r--src/gqueue/sys_rules.h23
4 files changed, 340 insertions, 0 deletions
diff --git a/src/gqueue/sys_defs.h b/src/gqueue/sys_defs.h
new file mode 100644
index 00000000..447ea5be
--- /dev/null
+++ b/src/gqueue/sys_defs.h
@@ -0,0 +1,264 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gqueue/sys_defs.h
+ * @brief GQUEUE header file.
+ *
+ * @addtogroup GQUEUE
+ *
+ * @brief Module which provides queue management (only internally used)
+ *
+ * @details There are 3 types of queues:
+ * <ul><li><b>Asynchronous Queues (ASync) </b> - Queue operations never block</li>
+ * <li><b>Get Synchronous Queues (GSync) </b> - Queue Get operations block until something is placed in the Queue</li>
+ * <li><b>Put Synchronous Queues (PSync)</b> - Queue Put operations block until the element is removed from the Queue</li>
+ * <li><b>Fully Synchronous Queues (FSync)</b> - Queue GET and Put operations block</li>
+ * </ul>
+ * We need 4 types of queues even though fully synchronous queues support all operations including asynchronous
+ * operations because fully synchronous queues have the highest storage requirements. The other queue types are
+ * optimizations. Efficiency IS important to use (particularly RAM efficiency).
+ * In practice we only implement ASync, GSync and FSync queues as PSync queues are of dubious value.
+ * @{
+ */
+
+#ifndef _GQUEUE_H
+#define _GQUEUE_H
+
+#if GFX_USE_GQUEUE || defined(__DOXYGEN__)
+
+/**
+ * @brief A queue
+ * @{
+ */
+typedef struct gfxQueueASync {
+ struct gfxQueueASyncItem *head;
+ struct gfxQueueASyncItem *tail;
+} gfxQueueASync;
+
+typedef struct gfxQueueGSync {
+ struct gfxQueueGSyncItem *head;
+ struct gfxQueueGSyncItem *tail;
+ gfxSem sem;
+} gfxQueueGSync;
+
+typedef struct gfxQueueFSync {
+ struct gfxQueueFSyncItem *head;
+ struct gfxQueueFSyncItem *tail;
+ gfxSem sem;
+} gfxQueueFSync;
+/* @} */
+
+/**
+ * @brief A queue item
+ * @{
+ */
+typedef struct gfxQueueASyncItem {
+ struct gfxQueueASyncItem *next;
+} gfxQueueASyncItem;
+
+typedef struct gfxQueueGSyncItem {
+ struct gfxQueueGSyncItem *next;
+} gfxQueueGSyncItem;
+
+typedef struct gfxQueueFSyncItem {
+ struct gfxQueueFSyncItem *next;
+ gfxSem sem;
+} gfxQueueFSyncItem;
+/* @} */
+
+
+/*===========================================================================*/
+/* Function declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Initialise a queue.
+ *
+ * @param[in] pqueue A pointer to the queue
+ *
+ * @note Whilst queues are normally FIFO, a GFX queue also supports push and pop operations.
+ * A pop operation is the same as normal get from the queue but a push places the item
+ * at the head of the queue instead of the tail (as a put would).
+ *
+ * @api
+ * @{
+ */
+void gfxQueueASyncInit(gfxQueueASync *pqueue);
+void gfxQueueGSyncInit(gfxQueueGSync *pqueue);
+void gfxQueueFSyncInit(gfxQueueFSync *pqueue);
+/* @} */
+
+/**
+ * @brief Get an item from the head of the queue (and remove it from the queue).
+ * @return NULL if the timeout expires before an item is available
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] ms The maxmimum time to wait for an item. For ASync queues this parameter is
+ * not specified as TIME_IMMEDIATE is assumed.
+ *
+ * @api
+ * @{
+ */
+gfxQueueASyncItem *gfxQueueASyncGet(gfxQueueASync *pqueue);
+gfxQueueGSyncItem *gfxQueueGSyncGet(gfxQueueGSync *pqueue, delaytime_t ms);
+gfxQueueFSyncItem *gfxQueueFSyncGet(gfxQueueFSync *pqueue, delaytime_t ms);
+/* @} */
+
+/**
+ * @brief Put an item on the end of the queue.
+ * @return none for ASync and GSync queues; For FSync queues - FALSE on timeout, otherwise TRUE
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] pitem A pointer to the queue item
+ * @param[in] ms The maxmimum time to wait for an item to be removed from the queue (only for FSync queues)
+ *
+ * @note FSync: Use a delay time of TIME_IMMEDIATE if you don't want to wait until the
+ * item is removed from the queue. Note that even if the timeout occurs - the item
+ * remains in the queue.
+ *
+ * @api
+ * @{
+ */
+void gfxQueueASyncPut(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem);
+void gfxQueueGSyncPut(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem);
+bool_t gfxQueueFSyncPut(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delaytime_t ms);
+/* @} */
+
+/**
+ * @brief Pop an item from the head of the queue (and remove it from the queue).
+ * @details This is exactly the same as the Get operation above.
+ *
+ * @api
+ * @{
+ */
+#define gfxQueueASyncPop(pqueue) gfxQueueASyncGet(pqueue)
+#define gfxQueueGSyncPop(pqueue, ms) gfxQueueGSyncGet(pqueue, ms)
+#define gfxQueueFSyncPop(pqueue, ms) gfxQueueFSyncGet(pqueue, ms)
+/* @} */
+
+/**
+ * @brief Push an item into the start of the queue.
+ * @return none for ASync and GSync queues; For FSync queues - FALSE on timeout, otherwise TRUE
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] pitem A pointer to the queue item
+ * @param[in] ms The maxmimum time to wait for an item to be popped (only for FSync queues)
+ *
+ * @note FSync: Use a delay time of TIME_IMMEDIATE if you don't want to wait until the
+ * item is removed from the queue. Note that even if the timeout occurs - the item
+ * remains in the queue.
+ *
+ * @api
+ * @{
+ */
+void gfxQueueASyncPush(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem);
+void gfxQueueGSyncPush(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem);
+bool_t gfxQueueFSyncPush(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delaytime_t ms);
+/* @} */
+
+/**
+ * @brief Remove an item from the queue.
+ * @note Removes the specified item from the queue where-ever it is in the queue
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] pitem A pointer to the queue item
+ *
+ * @note If the item isn't in the queue the routine just returns.
+ * @note If a process is waiting on the Put/Push operation for the item, that process
+ * will be signaled.
+ *
+ * @api
+ * @{
+ */
+void gfxQueueASyncRemove(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem);
+void gfxQueueGSyncRemove(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem);
+void gfxQueueFSyncRemove(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem);
+/* @} */
+
+/**
+ * @brief Is the queue empty?
+ * @return TRUE if the queue is empty
+ *
+ * @param[in] pqueue A pointer to the queue
+ *
+ * @api
+ * @{
+ */
+bool_t gfxQueueASyncIsEmpty(gfxQueueASync *pqueue);
+bool_t gfxQueueGSyncIsEmpty(gfxQueueGSync *pqueue);
+bool_t gfxQueueFSyncIsEmpty(gfxQueueFSync *pqueue);
+/* @} */
+
+/**
+ * @brief Is an item in the queue?
+ * @return TRUE if the item is in the queue?
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] pitem A pointer to the queue item
+ *
+ * @note This operation may be expensive.
+ *
+ * @api
+ * @{
+ */
+bool_t gfxQueueASyncIsIn(gfxQueueASync *pqueue, const gfxQueueASyncItem *pitem);
+bool_t gfxQueueGSyncIsIn(gfxQueueGSync *pqueue, const gfxQueueGSyncItem *pitem);
+bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem);
+/* @} */
+
+/**
+ * @brief Get the first item from the head of the queue but do not remove it from the queue.
+ * @return NULL if no item is available.
+ *
+ * @param[in] pqueue A pointer to the queue
+ *
+ * @note This call does not block.
+ * @note This can be used as the first call to iterate all the elements in the queue.
+ * @note As that item is still on the queue, it should be treated as read-only. It could
+ * also be removed from the queue at any time by another thread (thereby altering the
+ * queue item).
+ *
+ * @api
+ * @{
+ */
+#define gfxQueueASyncPeek(pqueue) ((const gfxQueueASyncItem *)((pqueue)->head))
+#define gfxQueueGSyncPeek(pqueue) ((const gfxQueueGSyncItem *)((pqueue)->head))
+#define gfxQueueFSyncPeek(pqueue) ((const gfxQueueFSyncItem *)((pqueue)->head))
+/* @} */
+
+/**
+ * @brief Get the next item in the queue (but do not remove it from the queue).
+ * @return NULL if no item is available.
+ *
+ * @param[in] pitem The previous item in the queue
+ *
+ * @note This call does not block.
+ * @note This can be used as subsequent calls to iterate all the elements in the queue.
+ * @note As that item is still on the queue, it should be treated as read-only. It could
+ * also be removed from the queue at any time by another thread (thereby altering the
+ * queue item).
+ *
+ * @api
+ * @{
+ */
+#define gfxQueueASyncNext(pitem) ((const gfxQueueASyncItem *)((pitem)->next))
+#define gfxQueueGSyncNext(pitem) ((const gfxQueueGSyncItem *)((pitem)->next))
+#define gfxQueueFSyncNext(pitem) ((const gfxQueueFSyncItem *)((pitem)->next))
+/* @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_GQUEUE */
+#endif /* _GQUEUE_H */
+/** @} */
diff --git a/src/gqueue/gqueue.mk b/src/gqueue/sys_make.mk
index ab8a0423..ab8a0423 100644
--- a/src/gqueue/gqueue.mk
+++ b/src/gqueue/sys_make.mk
diff --git a/src/gqueue/sys_options.h b/src/gqueue/sys_options.h
new file mode 100644
index 00000000..7c8627ce
--- /dev/null
+++ b/src/gqueue/sys_options.h
@@ -0,0 +1,53 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gqueue/sys_options.h
+ * @brief GQUEUE - Queue options header file.
+ *
+ * @addtogroup GQUEUE
+ * @{
+ */
+
+#ifndef _GQUEUE_OPTIONS_H
+#define _GQUEUE_OPTIONS_H
+
+/**
+ * @name GQUEUE Functions to include.
+ * @{
+ */
+ /**
+ * @brief Enable Asynchronous Queues
+ * @details Defaults to FALSE
+ */
+ #ifndef GQUEUE_NEED_ASYNC
+ #define GQUEUE_NEED_ASYNC FALSE
+ #endif
+ /**
+ * @brief Enable Get-Synchronous Queues
+ * @details Defaults to FALSE
+ */
+ #ifndef GQUEUE_NEED_GSYNC
+ #define GQUEUE_NEED_GSYNC FALSE
+ #endif
+ /**
+ * @brief Enable Fully Synchronous Queues
+ * @details Defaults to FALSE
+ */
+ #ifndef GQUEUE_NEED_FSYNC
+ #define GQUEUE_NEED_FSYNC FALSE
+ #endif
+/**
+ * @}
+ *
+ * @name GQUEUE Optional Sizing Parameters
+ * @{
+ */
+/** @} */
+
+#endif /* _GQUEUE_OPTIONS_H */
+/** @} */
diff --git a/src/gqueue/sys_rules.h b/src/gqueue/sys_rules.h
new file mode 100644
index 00000000..baeb073d
--- /dev/null
+++ b/src/gqueue/sys_rules.h
@@ -0,0 +1,23 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gqueue/sys_rules.h
+ * @brief GQUEUE safety rules header file.
+ *
+ * @addtogroup GQUEUE
+ * @{
+ */
+
+#ifndef _GQUEUE_RULES_H
+#define _GQUEUE_RULES_H
+
+#if GFX_USE_GQUEUE
+#endif
+
+#endif /* _GQUEUE_RULES_H */
+/** @} */