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/target/hosted/sdl/thread-sdl.c | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'firmware/target') diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c index c17e793833..eaf59e245d 100644 --- a/firmware/target/hosted/sdl/thread-sdl.c +++ b/firmware/target/hosted/sdl/thread-sdl.c @@ -406,20 +406,20 @@ void sleep_thread(int ticks) current->tmo_tick = (1000/HZ) * ticks + ((1000/HZ)-1) - rem; } -void block_thread(struct thread_entry *current) +void block_thread(struct thread_entry *current, int ticks) { - current->state = STATE_BLOCKED; - add_to_list_l(current->bqp, current); -} + if (ticks < 0) + current->state = STATE_BLOCKED; + else + { + current->state = STATE_BLOCKED_W_TMO; + current->tmo_tick = (1000/HZ)*ticks; + } -void block_thread_w_tmo(struct thread_entry *current, int ticks) -{ - current->state = STATE_BLOCKED_W_TMO; - current->tmo_tick = (1000/HZ)*ticks; add_to_list_l(current->bqp, current); } -unsigned int wakeup_thread(struct thread_entry **list) +unsigned int wakeup_thread_(struct thread_entry **list) { struct thread_entry *thread = *list; @@ -439,20 +439,26 @@ unsigned int wakeup_thread(struct thread_entry **list) return THREAD_NONE; } -unsigned int thread_queue_wake(struct thread_entry **list) +unsigned int thread_queue_wake(struct thread_entry **list, + volatile int *count) { unsigned int result = THREAD_NONE; + int num = 0; for (;;) { - unsigned int rc = wakeup_thread(list); + unsigned int rc = wakeup_thread_(list); if (rc == THREAD_NONE) break; - result |= rc; + result |= rc; + num++; } + if (count) + *count = num; + return result; } @@ -615,7 +621,7 @@ void remove_thread(unsigned int thread_id) new_thread_id(thread->id, thread); thread->state = STATE_KILLED; - thread_queue_wake(&thread->queue); + thread_queue_wake(&thread->queue, NULL); SDL_DestroySemaphore(s); @@ -652,7 +658,7 @@ void thread_wait(unsigned int thread_id) if (thread->id == thread_id && thread->state != STATE_KILLED) { current->bqp = &thread->queue; - block_thread(current); + block_thread(current, TIMEOUT_BLOCK); switch_thread(); } } -- cgit