[kernel] remove critical_section, move everything to spinlocks

This commit is contained in:
Travis Geiselbrecht
2014-05-10 21:35:49 -07:00
parent bf1d680063
commit 8fb2c54304
18 changed files with 194 additions and 173 deletions

View File

@@ -26,16 +26,16 @@ void sem_init(semaphore_t *sem, unsigned int value)
void sem_destroy(semaphore_t *sem)
{
enter_critical_section();
THREAD_LOCK(state);
sem->count = 0;
wait_queue_destroy(&sem->wait, true);
exit_critical_section();
THREAD_UNLOCK(state);
}
status_t sem_post(semaphore_t *sem, bool resched)
{
status_t ret = NO_ERROR;
enter_critical_section();
THREAD_LOCK(state);
/*
* If the count is or was negative then a thread is waiting for a resource, otherwise
@@ -44,14 +44,14 @@ status_t sem_post(semaphore_t *sem, bool resched)
if (unlikely(++sem->count <= 0))
wait_queue_wake_one(&sem->wait, resched, NO_ERROR);
exit_critical_section();
THREAD_UNLOCK(state);
return ret;
}
status_t sem_wait(semaphore_t *sem)
{
status_t ret = NO_ERROR;
enter_critical_section();
THREAD_LOCK(state);
/*
* If there are no resources available then we need to
@@ -60,28 +60,28 @@ status_t sem_wait(semaphore_t *sem)
if (unlikely(--sem->count < 0))
ret = wait_queue_block(&sem->wait, INFINITE_TIME);
exit_critical_section();
THREAD_UNLOCK(state);
return ret;
}
status_t sem_trywait(semaphore_t *sem)
{
status_t ret = NO_ERROR;
enter_critical_section();
THREAD_LOCK(state);
if (unlikely(sem->count <= 0))
ret = ERR_NOT_READY;
else
sem->count--;
exit_critical_section();
THREAD_UNLOCK(state);
return ret;
}
status_t sem_timedwait(semaphore_t *sem, lk_time_t timeout)
{
status_t ret = NO_ERROR;
enter_critical_section();
THREAD_LOCK(state);
if (unlikely(--sem->count < 0)) {
ret = wait_queue_block(&sem->wait, timeout);
@@ -92,6 +92,6 @@ status_t sem_timedwait(semaphore_t *sem, lk_time_t timeout)
}
}
exit_critical_section();
THREAD_UNLOCK(state);
return ret;
}