summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2015-05-13 13:24:52 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-05-26 19:36:15 +0000
commita0ebf0a008670ece41529a2fce01882192331c6e (patch)
treeaf15cc38acca1fa811d819aa327abcc7d415552a /common
parent2a4ac55edfbbbdcde605c323e07effcca5716e6f (diff)
downloadchrome-ec-a0ebf0a008670ece41529a2fce01882192331c6e.tar.gz
Queue: Add policies to queues
Policies give a convenient place to hook into the queue operations and notify something that there is new space free in the queue or new units added. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Change-Id: I94b2aa94b8e8d07911191bc19a39fa827623b117 Reviewed-on: https://chromium-review.googlesource.com/271791 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Trybot-Ready: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/keyboard_8042.c4
-rw-r--r--common/queue.c20
2 files changed, 22 insertions, 2 deletions
diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c
index d21b4ceae5..8affac4d8b 100644
--- a/common/keyboard_8042.c
+++ b/common/keyboard_8042.c
@@ -68,7 +68,7 @@ enum scancode_set_list {
*/
static struct mutex to_host_mutex;
-QUEUE_CONFIG(to_host, 16, uint8_t);
+static struct queue const to_host = QUEUE_NULL(16, uint8_t);
/* Queue command/data from the host */
enum {
@@ -91,7 +91,7 @@ struct host_byte {
*
* Hence, 5 (actually 4 plus one spare) is large enough, but use 8 for safety.
*/
-QUEUE_CONFIG(from_host, 8, struct host_byte);
+static struct queue const from_host = QUEUE_NULL(8, struct host_byte);
static int i8042_irq_enabled;
diff --git a/common/queue.c b/common/queue.c
index 70b4bd40d0..6e5e9e65ad 100644
--- a/common/queue.c
+++ b/common/queue.c
@@ -7,9 +7,21 @@
#include "queue.h"
#include "util.h"
+static void queue_action_null(struct queue_policy const *policy, size_t count)
+{
+}
+
+struct queue_policy const queue_policy_null = {
+ .add = queue_action_null,
+ .remove = queue_action_null,
+};
+
void queue_init(struct queue const *q)
{
ASSERT(POWER_OF_TWO(q->buffer_units));
+ ASSERT(q->policy);
+ ASSERT(q->policy->add);
+ ASSERT(q->policy->remove);
q->state->head = 0;
q->state->tail = 0;
@@ -44,6 +56,8 @@ size_t queue_add_unit(struct queue const *q, void const *src)
q->state->tail += 1;
+ q->policy->add(q->policy, 1);
+
return 1;
}
@@ -74,6 +88,8 @@ size_t queue_add_memcpy(struct queue const *q,
q->state->tail += transfer;
+ q->policy->add(q->policy, transfer);
+
return transfer;
}
@@ -111,6 +127,8 @@ size_t queue_remove_unit(struct queue const *q, void *dest)
q->state->head += 1;
+ q->policy->remove(q->policy, 1);
+
return 1;
}
@@ -133,6 +151,8 @@ size_t queue_remove_memcpy(struct queue const *q,
q->state->head += transfer;
+ q->policy->remove(q->policy, transfer);
+
return transfer;
}