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

@ -84,7 +84,7 @@ static void queue_release_sender(struct thread_entry * volatile * sender,
*thread->bqp = thread; /* Move blocking queue head to thread since
wakeup_thread wakes the first thread in
the list. */
wakeup_thread(thread->bqp);
wakeup_thread(thread->bqp, WAKEUP_RELEASE);
}
/* Releases any waiting threads that are queued with queue_send -
@ -108,16 +108,16 @@ static void queue_release_all_senders(struct event_queue *q)
}
}
#ifdef HAVE_WAKEUP_EXT_CB
/* Callback to do extra forced removal steps from sender list in addition
* to the normal blocking queue removal and priority dis-inherit */
static void queue_remove_sender_thread_cb(struct thread_entry *thread)
{
*((struct thread_entry **)thread->retval) = NULL;
#ifdef HAVE_WAKEUP_EXT_CB
thread->wakeup_ext_cb = NULL;
#endif
thread->retval = 0;
}
#endif /* HAVE_WAKEUP_EXT_CB */
/* Enables queue_send on the specified queue - caller allocates the extra
* data structure. Only queues which are taken to be owned by a thread should
@ -139,7 +139,6 @@ void queue_enable_queue_send(struct event_queue *q,
{
memset(send, 0, sizeof(*send));
#ifdef HAVE_PRIORITY_SCHEDULING
send->blocker.wakeup_protocol = wakeup_priority_protocol_release;
send->blocker.priority = PRIORITY_IDLE;
if(owner_id != 0)
{
@ -268,7 +267,7 @@ void queue_delete(struct event_queue *q)
corelock_unlock(&all_queues.cl);
/* Release thread(s) waiting on queue head */
thread_queue_wake(&q->queue);
thread_queue_wake(&q->queue, NULL);
#ifdef HAVE_EXTENDED_MESSAGING_AND_NAME
if(q->send)
@ -325,7 +324,7 @@ void queue_wait(struct event_queue *q, struct queue_event *ev)
IF_COP( current->obj_cl = &q->cl; )
current->bqp = &q->queue;
block_thread(current);
block_thread(current, TIMEOUT_BLOCK);
corelock_unlock(&q->cl);
switch_thread();
@ -386,7 +385,7 @@ void queue_wait_w_tmo(struct event_queue *q, struct queue_event *ev, int ticks)
IF_COP( current->obj_cl = &q->cl; )
current->bqp = &q->queue;
block_thread_w_tmo(current, ticks);
block_thread(current, ticks);
corelock_unlock(&q->cl);
switch_thread();
@ -443,7 +442,7 @@ void queue_post(struct event_queue *q, long id, intptr_t data)
queue_do_unblock_sender(q->send, wr);
/* Wakeup a waiting thread if any */
wakeup_thread(&q->queue);
wakeup_thread(&q->queue, WAKEUP_DEFAULT);
corelock_unlock(&q->cl);
restore_irq(oldlevel);
@ -481,7 +480,7 @@ intptr_t queue_send(struct event_queue *q, long id, intptr_t data)
}
/* Wakeup a waiting thread if any */
wakeup_thread(&q->queue);
wakeup_thread(&q->queue, WAKEUP_DEFAULT);
/* Save thread in slot, add to list and wait for reply */
*spp = current;
@ -493,7 +492,7 @@ intptr_t queue_send(struct event_queue *q, long id, intptr_t data)
current->retval = (intptr_t)spp;
current->bqp = &send->list;
block_thread(current);
block_thread(current, TIMEOUT_BLOCK);
corelock_unlock(&q->cl);
switch_thread();
@ -502,7 +501,7 @@ intptr_t queue_send(struct event_queue *q, long id, intptr_t data)
}
/* Function as queue_post if sending is not enabled */
wakeup_thread(&q->queue);
wakeup_thread(&q->queue, WAKEUP_DEFAULT);
corelock_unlock(&q->cl);
restore_irq(oldlevel);