1
0
Fork 0
forked from len0rd/rockbox

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>
This commit is contained in:
Michael Sevakis 2014-04-24 04:09:18 -04:00
parent 6536f1db3e
commit 533d396761
11 changed files with 880 additions and 601 deletions

View file

@ -28,20 +28,14 @@
struct mutex
{
struct thread_entry *queue; /* waiter list */
int recursion; /* lock owner recursion count */
struct thread_entry *queue; /* waiter list */
int recursion; /* lock owner recursion count */
struct blocker blocker; /* priority inheritance info
for waiters and owner*/
IF_COP( struct corelock cl; ) /* multiprocessor sync */
#ifdef HAVE_PRIORITY_SCHEDULING
struct blocker blocker; /* priority inheritance info
for waiters */
bool no_preempt; /* don't allow higher-priority thread
to be scheduled even if woken */
#else
struct thread_entry *thread; /* Indicates owner thread - an owner
implies a locked state - same goes
for priority scheduling
(in blocker struct for that) */
bool no_preempt;
#endif
IF_COP( struct corelock cl; ) /* multiprocessor sync */
};
extern void mutex_init(struct mutex *m);
@ -56,7 +50,7 @@ static inline void mutex_set_preempt(struct mutex *m, bool preempt)
#else
/* Deprecated but needed for now - firmware/drivers/ata_mmc.c */
static inline bool mutex_test(const struct mutex *m)
{ return m->thread != NULL; }
{ return m->blocker.thread != NULL; }
#endif /* HAVE_PRIORITY_SCHEDULING */
#endif /* MUTEX_H */