forked from len0rd/rockbox
Base scheduler queues off linked lists and do cleanup/consolidation
Abstracts threading from itself a bit, changes the way its queues are handled and does type hiding for that as well. Do alot here due to already required major brain surgery. Threads may now be on a run queue and a wait queue simultaneously so that the expired timer only has to wake the thread but not remove it from the wait queue which simplifies the implicit wake handling. List formats change for wait queues-- doubly-linked, not circular. Timeout queue is now singly-linked. The run queue is still circular as before. Adds a better thread slot allocator that may keep the slot marked as used regardless of the thread state. Assists in dumping special tasks that switch_thread was tasked to perform (blocking tasks). Deletes alot of code yet surprisingly, gets larger than expected. Well, I'm not not minding that for the time being-- omlettes and break a few eggs and all that. Change-Id: I0834d7bb16b2aecb2f63b58886eeda6ae4f29d59
This commit is contained in:
parent
eb63d8b4a2
commit
6ed00870ab
20 changed files with 1550 additions and 2057 deletions
|
@ -30,20 +30,19 @@
|
|||
* the object is available to other threads */
|
||||
void mutex_init(struct mutex *m)
|
||||
{
|
||||
corelock_init(&m->cl);
|
||||
m->queue = NULL;
|
||||
wait_queue_init(&m->queue);
|
||||
m->recursion = 0;
|
||||
m->blocker.thread = NULL;
|
||||
blocker_init(&m->blocker);
|
||||
#ifdef HAVE_PRIORITY_SCHEDULING
|
||||
m->blocker.priority = PRIORITY_IDLE;
|
||||
m->no_preempt = false;
|
||||
#endif
|
||||
corelock_init(&m->cl);
|
||||
}
|
||||
|
||||
/* Gain ownership of a mutex object or block until it becomes free */
|
||||
void mutex_lock(struct mutex *m)
|
||||
{
|
||||
struct thread_entry *current = thread_self_entry();
|
||||
struct thread_entry *current = __running_self_entry();
|
||||
|
||||
if(current == m->blocker.thread)
|
||||
{
|
||||
|
@ -65,12 +64,8 @@ void mutex_lock(struct mutex *m)
|
|||
}
|
||||
|
||||
/* block until the lock is open... */
|
||||
IF_COP( current->obj_cl = &m->cl; )
|
||||
IF_PRIO( current->blocker = &m->blocker; )
|
||||
current->bqp = &m->queue;
|
||||
|
||||
disable_irq();
|
||||
block_thread(current, TIMEOUT_BLOCK);
|
||||
block_thread(current, TIMEOUT_BLOCK, &m->queue, &m->blocker);
|
||||
|
||||
corelock_unlock(&m->cl);
|
||||
|
||||
|
@ -82,10 +77,10 @@ void mutex_lock(struct mutex *m)
|
|||
void mutex_unlock(struct mutex *m)
|
||||
{
|
||||
/* unlocker not being the owner is an unlocking violation */
|
||||
KERNEL_ASSERT(m->blocker.thread == thread_self_entry(),
|
||||
KERNEL_ASSERT(m->blocker.thread == __running_self_entry(),
|
||||
"mutex_unlock->wrong thread (%s != %s)\n",
|
||||
m->blocker.thread->name,
|
||||
thread_self_entry()->name);
|
||||
__running_self_entry()->name);
|
||||
|
||||
if(m->recursion > 0)
|
||||
{
|
||||
|
@ -98,7 +93,8 @@ void mutex_unlock(struct mutex *m)
|
|||
corelock_lock(&m->cl);
|
||||
|
||||
/* transfer to next queued thread if any */
|
||||
if(LIKELY(m->queue == NULL))
|
||||
struct thread_entry *thread = WQ_THREAD_FIRST(&m->queue);
|
||||
if(LIKELY(thread == NULL))
|
||||
{
|
||||
/* no threads waiting - open the lock */
|
||||
m->blocker.thread = NULL;
|
||||
|
@ -107,11 +103,7 @@ void mutex_unlock(struct mutex *m)
|
|||
}
|
||||
|
||||
const int oldlevel = disable_irq_save();
|
||||
/* Tranfer of owning thread is handled in the wakeup protocol
|
||||
* if priorities are enabled otherwise just set it from the
|
||||
* queue head. */
|
||||
IFN_PRIO( m->blocker.thread = m->queue; )
|
||||
unsigned int result = wakeup_thread(&m->queue, WAKEUP_TRANSFER);
|
||||
unsigned int result = wakeup_thread(thread, WAKEUP_TRANSFER);
|
||||
restore_irq(oldlevel);
|
||||
|
||||
corelock_unlock(&m->cl);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue