diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2014-04-24 04:09:18 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2014-08-06 02:47:47 +0200 |
commit | 533d396761b630e372166f6f0522ba1c2d128d70 (patch) | |
tree | 823a5f800049f62d4ea9f573b4cdeb3e7ff9b3e1 /firmware/kernel/include/mutex.h | |
parent | 6536f1db3eedf0a12d16c5504cba94725eb6500d (diff) | |
download | rockbox-533d396761b630e372166f6f0522ba1c2d128d70.tar.gz rockbox-533d396761b630e372166f6f0522ba1c2d128d70.zip |
Add multi-reader, single-writer locks to kernel.
Any number of readers may be in the critical section at a time and writers
are mutually exclusive to all other threads. They are a better choice when
data is rarely modified but often read and multiple threads can safely
access it for reading.
Priority inheritance is fully implemented along with other changes to the
kernel to fully support it on multiowner objects.
This also cleans up priority code in the kernel and updates some associated
structures in existing objects to the cleaner form.
Currently doesn't add the mrsw_lock.[ch] files since they're not yet
needed by anything but the supporting improvements are still useful.
This includes a typed bitarray API (bitarray.h) which is pretty basic
for now.
Change-Id: Idbe43dcd9170358e06d48d00f1c69728ff45b0e3
Reviewed-on: http://gerrit.rockbox.org/801
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'firmware/kernel/include/mutex.h')
-rw-r--r-- | firmware/kernel/include/mutex.h | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/firmware/kernel/include/mutex.h b/firmware/kernel/include/mutex.h index bcf5701bd9..02b85f331f 100644 --- a/firmware/kernel/include/mutex.h +++ b/firmware/kernel/include/mutex.h | |||
@@ -28,20 +28,14 @@ | |||
28 | 28 | ||
29 | struct mutex | 29 | struct mutex |
30 | { | 30 | { |
31 | struct thread_entry *queue; /* waiter list */ | 31 | struct thread_entry *queue; /* waiter list */ |
32 | int recursion; /* lock owner recursion count */ | 32 | int recursion; /* lock owner recursion count */ |
33 | struct blocker blocker; /* priority inheritance info | ||
34 | for waiters and owner*/ | ||
35 | IF_COP( struct corelock cl; ) /* multiprocessor sync */ | ||
33 | #ifdef HAVE_PRIORITY_SCHEDULING | 36 | #ifdef HAVE_PRIORITY_SCHEDULING |
34 | struct blocker blocker; /* priority inheritance info | 37 | bool no_preempt; |
35 | for waiters */ | ||
36 | bool no_preempt; /* don't allow higher-priority thread | ||
37 | to be scheduled even if woken */ | ||
38 | #else | ||
39 | struct thread_entry *thread; /* Indicates owner thread - an owner | ||
40 | implies a locked state - same goes | ||
41 | for priority scheduling | ||
42 | (in blocker struct for that) */ | ||
43 | #endif | 38 | #endif |
44 | IF_COP( struct corelock cl; ) /* multiprocessor sync */ | ||
45 | }; | 39 | }; |
46 | 40 | ||
47 | extern void mutex_init(struct mutex *m); | 41 | extern void mutex_init(struct mutex *m); |
@@ -56,7 +50,7 @@ static inline void mutex_set_preempt(struct mutex *m, bool preempt) | |||
56 | #else | 50 | #else |
57 | /* Deprecated but needed for now - firmware/drivers/ata_mmc.c */ | 51 | /* Deprecated but needed for now - firmware/drivers/ata_mmc.c */ |
58 | static inline bool mutex_test(const struct mutex *m) | 52 | static inline bool mutex_test(const struct mutex *m) |
59 | { return m->thread != NULL; } | 53 | { return m->blocker.thread != NULL; } |
60 | #endif /* HAVE_PRIORITY_SCHEDULING */ | 54 | #endif /* HAVE_PRIORITY_SCHEDULING */ |
61 | 55 | ||
62 | #endif /* MUTEX_H */ | 56 | #endif /* MUTEX_H */ |