[kernel] add sem_timedwait

This commit is contained in:
Chris Anderson
2012-10-17 17:32:29 -07:00
parent e465a4f0c5
commit 71af6dc77d
2 changed files with 19 additions and 1 deletions

View File

@@ -63,4 +63,21 @@ status_t sem_trywait(semaphore_t *sem)
exit_critical_section();
return ret;
}
status_t sem_timedwait(semaphore_t *sem, lk_time_t timeout)
{
status_t ret = NO_ERROR;
enter_critical_section();
if (--sem->count < 0) {
ret = wait_queue_block(&sem->wait, timeout);
if (ret < NO_ERROR) {
if (ret == ERR_TIMED_OUT) {
sem->count++;
}
}
}
exit_critical_section();
return ret;
}