[kernel][sem] a few microoptimizations to hint at the compiler which path to take

This commit is contained in:
Travis Geiselbrecht
2012-10-17 21:01:58 -07:00
parent 71af6dc77d
commit eda348c06c

View File

@@ -27,7 +27,7 @@ status_t sem_post(semaphore_t *sem)
* If the count is or was negative then a thread is waiting for a resource, otherwise
* it's safe to just increase the count available with no downsides
*/
if (++sem->count <= 0)
if (unlikely(++sem->count <= 0))
wait_queue_wake_one(&sem->wait, true, NO_ERROR);
exit_critical_section();
@@ -43,7 +43,7 @@ status_t sem_wait(semaphore_t *sem)
* If there are no resources available then we need to
* sit in the wait queue until sem_post adds some.
*/
if (--sem->count < 0)
if (unlikely(--sem->count < 0))
ret = wait_queue_block(&sem->wait, INFINITE_TIME);
exit_critical_section();
@@ -55,7 +55,7 @@ status_t sem_trywait(semaphore_t *sem)
status_t ret = NO_ERROR;
enter_critical_section();
if (sem->count <= 0)
if (unlikely(sem->count <= 0))
ret = ERR_NOT_READY;
else
sem->count--;
@@ -69,7 +69,7 @@ status_t sem_timedwait(semaphore_t *sem, lk_time_t timeout)
status_t ret = NO_ERROR;
enter_critical_section();
if (--sem->count < 0) {
if (unlikely(--sem->count < 0)) {
ret = wait_queue_block(&sem->wait, timeout);
if (ret < NO_ERROR) {
if (ret == ERR_TIMED_OUT) {