diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2012-01-10 18:32:45 +0000 |
---|---|---|
committer | Vincent Palatin <vpalatin@chromium.org> | 2012-01-25 18:23:48 +0000 |
commit | 16e43a3d0d902f6c2771a2362f7e7dd40b3ddeee (patch) | |
tree | fb870f709bb43a9ddb8bf2f2865a81ff3c8f1432 /include | |
parent | d356dea61ee170366acddc373953dad20f6fc48e (diff) | |
download | chrome-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')
-rw-r--r-- | include/task.h | 15 | ||||
-rw-r--r-- | include/task_id.h | 1 |
2 files changed, 16 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; diff --git a/include/task_id.h b/include/task_id.h index 8b6e14721f..a2fb17ca7a 100644 --- a/include/task_id.h +++ b/include/task_id.h @@ -32,6 +32,7 @@ enum { /* Number of tasks */ TASK_ID_COUNT, /* Special task identifiers */ + TASK_ID_MUTEX = 0x1e, /* signal mutex unlocking */ TASK_ID_TIMER = 0x1f, /* message from an expired timer */ TASK_ID_CURRENT = 0xfe, /* the currently running task */ TASK_ID_INVALID = 0xff /* unable to find the task */ |