From e79e7f28dd4ff42546228dfead08d392c6177f93 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Tue, 4 Apr 2017 13:40:53 +0000 Subject: Be safe... if we had a super small timeout then by the time we call us, we could have blown past it... in that case, just try the lock git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1790111 13f79535-47bb-0310-9956-ffa450edef68 --- locks/unix/misc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'locks') diff --git a/locks/unix/misc.c b/locks/unix/misc.c index 3aacfe71d..84a4a073a 100644 --- a/locks/unix/misc.c +++ b/locks/unix/misc.c @@ -50,6 +50,10 @@ int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_t remaining.tv_sec--; remaining.tv_nsec = (NANOSECS_PER_SEC - (tod.tv_nsec - remaining.tv_nsec)); } + /* If we had a REALLY small timeout ;) */ + if (remaining.tv_sec < 0) { + return pthread_mutex_trylock(mutex); + } while ((rv = pthread_mutex_trylock(mutex)) == EBUSY) { ts.tv_sec = 0; ts.tv_nsec = (remaining.tv_sec > 0 ? SLEEP_TIME_NS : -- cgit v1.2.1