]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/thread.c
Migrate Windows conditional code to _WIN32 define.
[thirdparty/cups.git] / cups / thread.c
index bd947b4ecdb0103e254f9f70a1700f209caa1e63..fcab9382676857751e56a42cf52ea87b6a0e4374 100644 (file)
@@ -1,15 +1,10 @@
 /*
  * Threading primitives for CUPS.
  *
- * Copyright 2009-2016 by Apple Inc.
+ * Copyright © 2009-2018 by Apple Inc.
  *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file.  If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
@@ -56,8 +51,16 @@ _cupsCondWait(_cups_cond_t  *cond,   /* I - Condition */
   {
     struct timespec abstime;           /* Timeout */
 
-    abstime.tv_sec  = (long)timeout;
-    abstime.tv_nsec = (long)(1000000000 * (timeout - (long)timeout));
+    clock_gettime(CLOCK_REALTIME, &abstime);
+
+    abstime.tv_sec  += (long)timeout;
+    abstime.tv_nsec += (long)(1000000000 * (timeout - (long)timeout));
+
+    while (abstime.tv_nsec >= 1000000000)
+    {
+      abstime.tv_nsec -= 1000000000;
+      abstime.tv_sec ++;
+    };
 
     pthread_cond_timedwait(cond, mutex, &abstime);
   }
@@ -172,6 +175,17 @@ _cupsThreadCreate(
 }
 
 
+/*
+ * '_cupsThreadDetach()' - Tell the OS that the thread is running independently.
+ */
+
+void
+_cupsThreadDetach(_cups_thread_t thread)/* I - Thread ID */
+{
+  pthread_detach(thread);
+}
+
+
 /*
  * '_cupsThreadWait()' - Wait for a thread to exit.
  */
@@ -189,10 +203,45 @@ _cupsThreadWait(_cups_thread_t thread)    /* I - Thread ID */
 }
 
 
-#elif defined(WIN32)
+#elif defined(_WIN32)
 #  include <process.h>
 
 
+/*
+ * '_cupsCondBroadcast()' - Wake up waiting threads.
+ */
+
+void
+_cupsCondBroadcast(_cups_cond_t *cond) /* I - Condition */
+{
+  // TODO: Implement me
+}
+
+
+/*
+ * '_cupsCondInit()' - Initialize a condition variable.
+ */
+
+void
+_cupsCondInit(_cups_cond_t *cond)      /* I - Condition */
+{
+  // TODO: Implement me
+}
+
+
+/*
+ * '_cupsCondWait()' - Wait for a condition with optional timeout.
+ */
+
+void
+_cupsCondWait(_cups_cond_t  *cond,     /* I - Condition */
+              _cups_mutex_t *mutex,    /* I - Mutex */
+             double        timeout)    /* I - Timeout in seconds (0 or negative for none) */
+{
+  // TODO: Implement me
+}
+
+
 /*
  * '_cupsMutexInit()' - Initialize a mutex.
  */
@@ -308,18 +357,68 @@ _cupsThreadCreate(
 }
 
 
+/*
+ * '_cupsThreadDetach()' - Tell the OS that the thread is running independently.
+ */
+
+void
+_cupsThreadDetach(_cups_thread_t thread)/* I - Thread ID */
+{
+  // TODO: Implement me
+  (void)thread;
+}
+
+
 /*
  * '_cupsThreadWait()' - Wait for a thread to exit.
  */
 
 void *                                 /* O - Return value */
 _cupsThreadWait(_cups_thread_t thread) /* I - Thread ID */
+{
+  // TODO: Implement me
+  (void)thread;
+
+  return (NULL);
+}
+
+
+#else /* No threading */
+/*
+ * '_cupsCondBroadcast()' - Wake up waiting threads.
+ */
+
+void
+_cupsCondBroadcast(_cups_cond_t *cond) /* I - Condition */
+{
+  // TODO: Implement me
+}
+
+
+/*
+ * '_cupsCondInit()' - Initialize a condition variable.
+ */
+
+void
+_cupsCondInit(_cups_cond_t *cond)      /* I - Condition */
+{
+  // TODO: Implement me
+}
+
+
+/*
+ * '_cupsCondWait()' - Wait for a condition with optional timeout.
+ */
+
+void
+_cupsCondWait(_cups_cond_t  *cond,     /* I - Condition */
+              _cups_mutex_t *mutex,    /* I - Mutex */
+             double        timeout)    /* I - Timeout in seconds (0 or negative for none) */
 {
   // TODO: Implement me
 }
 
 
-#else
 /*
  * '_cupsMutexInit()' - Initialize a mutex.
  */
@@ -417,8 +516,7 @@ _cupsThreadCreate(
     _cups_thread_func_t func,          /* I - Entry point */
     void                *arg)          /* I - Entry point context */
 {
-  fputs("DEBUG: CUPS was compiled without threading support, no thread "
-        "created.\n", stderr);
+  fputs("DEBUG: CUPS was compiled without threading support, no thread created.\n", stderr);
 
   (void)func;
   (void)arg;
@@ -427,6 +525,17 @@ _cupsThreadCreate(
 }
 
 
+/*
+ * '_cupsThreadDetach()' - Tell the OS that the thread is running independently.
+ */
+
+void
+_cupsThreadDetach(_cups_thread_t thread)/* I - Thread ID */
+{
+  (void)thread;
+}
+
+
 /*
  * '_cupsThreadWait()' - Wait for a thread to exit.
  */