summaryrefslogtreecommitdiff
path: root/cups/thread.c
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2018-03-12 21:56:12 -0400
committerMichael R Sweet <michael.r.sweet@gmail.com>2018-03-12 21:56:12 -0400
commit13ceaad2735173e9cb639557fdcd35f8d6df2435 (patch)
treee24bbba951c47f572c86778280a3f175f2df02f7 /cups/thread.c
parent32987439c3dedb1dc03dabc943442fece7ec3d86 (diff)
downloadcups-13ceaad2735173e9cb639557fdcd35f8d6df2435.tar.gz
Fix implementation of _cupsCondWait with timeout.
Diffstat (limited to 'cups/thread.c')
-rw-r--r--cups/thread.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/cups/thread.c b/cups/thread.c
index 54ebc100b..c52f77710 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);
}