mirror of
https://github.com/minetest/minetest.git
synced 2025-01-11 07:47:31 +01:00
Optimize semaphore wait with zero timeout on POSIX
This commit is contained in:
parent
b5f5e00b29
commit
49365b25d9
@ -140,6 +140,8 @@ bool Semaphore::wait(unsigned int time_ms)
|
|||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
|
int ret;
|
||||||
|
if (time_ms > 0) {
|
||||||
struct timespec wait_time;
|
struct timespec wait_time;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
|
||||||
@ -152,10 +154,13 @@ bool Semaphore::wait(unsigned int time_ms)
|
|||||||
wait_time.tv_sec = (time_ms / 1000) + (wait_time.tv_nsec / (1000 * 1000 * 1000)) + now.tv_sec;
|
wait_time.tv_sec = (time_ms / 1000) + (wait_time.tv_nsec / (1000 * 1000 * 1000)) + now.tv_sec;
|
||||||
wait_time.tv_nsec %= 1000 * 1000 * 1000;
|
wait_time.tv_nsec %= 1000 * 1000 * 1000;
|
||||||
|
|
||||||
int ret = sem_timedwait(&semaphore, &wait_time);
|
ret = sem_timedwait(&semaphore, &wait_time);
|
||||||
|
} else {
|
||||||
|
ret = sem_trywait(&semaphore);
|
||||||
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
assert(!ret || (errno == ETIMEDOUT || errno == EINTR));
|
assert(!ret || (errno == ETIMEDOUT || errno == EINTR || errno == EAGAIN));
|
||||||
return !ret;
|
return !ret;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user