summaryrefslogtreecommitdiff
path: root/include/task.h
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2012-01-10 18:32:45 +0000
committerVincent Palatin <vpalatin@chromium.org>2012-01-25 18:23:48 +0000
commit16e43a3d0d902f6c2771a2362f7e7dd40b3ddeee (patch)
treefb870f709bb43a9ddb8bf2f2865a81ff3c8f1432 /include/task.h
parentd356dea61ee170366acddc373953dad20f6fc48e (diff)
downloadchrome-ec-16e43a3d0d902f6c2771a2362f7e7dd40b3ddeee.tar.gz
Initial mutex implementation
They are designed to protect shared hardware resources (e.g. I2C controller). Please refrain using them as a general purpose synchronization primitive for the tasks to avoid unintended slippery effects (e.g. priority inversion), use the provided message-passing functions instead for that purpose. The mutex variable (ie the "struct mutex") should be initially filled with 0, but this is the default compiler behavior if you declare it as a global variable. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=None TEST=make qemu-tests Change-Id: I328f7eadf5257560944dbbbeda0b99d5b24520e8
Diffstat (limited to 'include/task.h')
-rw-r--r--include/task.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/task.h b/include/task.h
index 7e1d001f11..5cf3336841 100644
--- a/include/task.h
+++ b/include/task.h
@@ -81,6 +81,21 @@ void task_disable_irq(int irq);
/* Software-triggers an interrupt. */
void task_trigger_irq(int irq);
+struct mutex {
+ uint32_t lock;
+ uint32_t waiters;
+};
+
+/**
+ * try to lock the mutex mtx
+ * and de-schedule the task if it is already locked by another task.
+ *
+ * Should not be used in interrupt context !
+ */
+void mutex_lock(struct mutex *mtx);
+
+/* Release a mutex previously locked by the same task. */
+void mutex_unlock(struct mutex *mtx);
struct irq_priority {
uint8_t irq;