mutex: don't rely on malloc for waitqueue
This commit is contained in:
parent
b7e9187740
commit
8293d9372b
1 changed files with 4 additions and 8 deletions
|
@ -20,15 +20,12 @@ void mutex_init(struct mutex *mutex)
|
||||||
void mutex_lock(struct mutex *mutex)
|
void mutex_lock(struct mutex *mutex)
|
||||||
{
|
{
|
||||||
if (mutex_trylock(mutex) != 0) {
|
if (mutex_trylock(mutex) != 0) {
|
||||||
struct mutex_wait *entry = malloc(sizeof(*entry));
|
struct mutex_wait entry = {
|
||||||
if (entry == NULL) {
|
.task = current,
|
||||||
_spin_lock(&mutex->lock); /* fall back to spinning */
|
};
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock(&mutex->wait_queue_lock);
|
spin_lock(&mutex->wait_queue_lock);
|
||||||
entry->task = current;
|
list_insert(&mutex->wait_queue, &entry.link);
|
||||||
list_insert(&mutex->wait_queue, &entry->link);
|
|
||||||
spin_unlock(&mutex->wait_queue_lock);
|
spin_unlock(&mutex->wait_queue_lock);
|
||||||
|
|
||||||
yield(TASK_LOCKWAIT);
|
yield(TASK_LOCKWAIT);
|
||||||
|
@ -48,7 +45,6 @@ void mutex_unlock(struct mutex *mutex)
|
||||||
|
|
||||||
if (waiter != NULL) {
|
if (waiter != NULL) {
|
||||||
struct task *task = waiter->task;
|
struct task *task = waiter->task;
|
||||||
free(waiter);
|
|
||||||
current->state = TASK_QUEUE;
|
current->state = TASK_QUEUE;
|
||||||
do_switch(current, task);
|
do_switch(current, task);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue