add interface for timedwait on semaphores
According to SDL documentation, the SDL implementation of timedwait may suck on some platforms, so it should only be used, where high CPU usage during the wait is no issue. getpckserver() will now only wait for one second for access to the package server list and return an error instead of waiting indefinitely.
This commit is contained in:
@@ -543,6 +543,11 @@ int sl_semaphore::trywait()
|
||||
return SDL_SemTryWait((SDL_sem *) data);
|
||||
}
|
||||
|
||||
int sl_semaphore::timedwait(int howlongmillis)
|
||||
{
|
||||
return SDL_SemWaitTimeout((SDL_sem *) data, howlongmillis);
|
||||
}
|
||||
|
||||
int sl_semaphore::getvalue()
|
||||
{
|
||||
return SDL_SemValue((SDL_sem *) data);
|
||||
@@ -579,6 +584,20 @@ int sl_semaphore::trywait()
|
||||
return sem_trywait((sem_t *) data);
|
||||
}
|
||||
|
||||
int sl_semaphore::timedwait(int howlongmillis)
|
||||
{
|
||||
struct timespec t;
|
||||
if(clock_gettime(CLOCK_REALTIME, &t))
|
||||
{
|
||||
(*errorcount)++;
|
||||
return sem_trywait((sem_t *) data);
|
||||
}
|
||||
howlongmillis += t.tv_nsec / 1000000;
|
||||
t.tv_nsec = (howlongmillis % 1000) * 1000000;
|
||||
t.tv_sec += howlongmillis / 1000;
|
||||
return sem_timedwait((sem_t *) data, &t);
|
||||
}
|
||||
|
||||
int sl_semaphore::getvalue()
|
||||
{
|
||||
int ret;
|
||||
|
||||
Reference in New Issue
Block a user