From: Michael R Sweet Date: Tue, 13 Mar 2018 01:56:12 +0000 (-0400) Subject: Fix implementation of _cupsCondWait with timeout. X-Git-Tag: v2.3b4~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13ceaad2735173e9cb639557fdcd35f8d6df2435;p=thirdparty%2Fcups.git Fix implementation of _cupsCondWait with timeout. --- diff --git a/cups/thread.c b/cups/thread.c index 54ebc100b7..c52f77710d 100644 --- a/cups/thread.c +++ b/cups/thread.c @@ -1,9 +1,10 @@ /* * Threading primitives for CUPS. * - * Copyright 2009-2017 by Apple Inc. + * Copyright © 2009-2018 by Apple Inc. * - * Licensed under Apache License v2.0. See the file "LICENSE" for more information. + * Licensed under Apache License v2.0. See the file "LICENSE" for more + * information. */ /* @@ -48,10 +49,19 @@ _cupsCondWait(_cups_cond_t *cond, /* I - Condition */ { if (timeout > 0.0) { + struct timeval curtime; /* Current time */ struct timespec abstime; /* Timeout */ - abstime.tv_sec = (long)timeout; - abstime.tv_nsec = (long)(1000000000 * (timeout - (long)timeout)); + gettimeofday(&curtime, NULL); + + abstime.tv_sec = (long)timeout + curtime.tv_sec; + abstime.tv_nsec = (long)(1000000000 * (timeout - (long)timeout + 1000 * curtime.tv_usec)); + + while (abstime.tv_nsec >= 1000000000) + { + abstime.tv_nsec -= 1000000000; + abstime.tv_sec ++; + }; pthread_cond_timedwait(cond, mutex, &abstime); }