From 533d396761b630e372166f6f0522ba1c2d128d70 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 24 Apr 2014 04:09:18 -0400 Subject: 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 Tested: Michael Sevakis --- firmware/kernel/include/mutex.h | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'firmware/kernel/include/mutex.h') 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 @@ 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 */ -- cgit v1.2.3