summaryrefslogtreecommitdiff
path: root/include/queue.h
diff options
context:
space:
mode:
authorLouis Yung-Chieh Lo <yjlou@chromium.org>2012-06-01 16:33:58 +0800
committerGerrit <chrome-bot@google.com>2012-06-07 20:48:51 -0700
commit210ddfefcfe90944c70105463beb6f795513c5e6 (patch)
treed979799b7cdf940bfadaaeb5e258e24b0841c299 /include/queue.h
parentc4ac74a11dfa66d6ad725833e2aac6579b0c76ed (diff)
downloadchrome-ec-210ddfefcfe90944c70105463beb6f795513c5e6.tar.gz
Refactor the i8042 module to be thread-safe.
Any command/data coming from host will be placed in from_host queue, and the interrupt handler returns immediately. The i8042_command_task() will handle them later. Data reply to the host will be protected by the mutex. BUG=chrome-os-partner:10090 TEST=randomly play around on the link board. Change-Id: Ic19d5abd1abf8dc261ddaad4224cd9305c2f36a4 Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/24299 Commit-Ready: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com> Reviewed-by: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com> Tested-by: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com>
Diffstat (limited to 'include/queue.h')
-rw-r--r--include/queue.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/include/queue.h b/include/queue.h
new file mode 100644
index 0000000000..2c967ee4a8
--- /dev/null
+++ b/include/queue.h
@@ -0,0 +1,40 @@
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Queue data structure.
+ */
+
+#include "common.h"
+
+/* Generic queue container.
+ *
+ * head: next to dequeqe
+ * tail: next to enqueue
+ *
+ * Empty:
+ * head == tail
+ * Full:
+ * ((tail + 1) % buf_bytes) == head
+ */
+struct queue {
+ int head, tail;
+ int buf_bytes; /* size of buffer (in byte) */
+ int unit_bytes; /* size of unit (in byte) */
+ uint8_t *buf;
+};
+
+/* Reset the queue to empty state. */
+void queue_reset(struct queue *queue);
+
+/* Return TRUE if the queue is empty. */
+int queue_is_empty(const struct queue *q);
+
+/* Return TRUE if the queue has at least one unit space. */
+int queue_has_space(const struct queue *q, int unit_count);
+
+/* Add multiple units into queue. */
+void queue_add_units(struct queue *q, const void *src, int unit_count);
+
+/* Remove one unit from the begin of the queue. */
+int queue_remove_unit(struct queue *q, void *dest);