]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/thread.c
Import experimental work-in-progress HTTP/2 branch
[thirdparty/cups.git] / cups / thread.c
index deb3a8ebc972169b206472db4be7ff1f8bb1cd49..3f430b65f17ae335bc1ac0b47467b2d0b6fb6bf1 100644 (file)
@@ -1,21 +1,17 @@
 /*
- * "$Id$"
+ * "$Id: thread.c 11984 2014-07-02 13:16:59Z msweet $"
  *
- *   Threading primitives for CUPS.
+ * Threading primitives for CUPS.
  *
- *   Copyright 2009-2010 by Apple Inc.
+ * Copyright 2009-2014 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/".
+ * 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/".
  *
- * Contents:
- *
- *   _cupsMutexLock()    - Lock a mutex.
- *   _cupsMutexUnlock()  - Unlock a mutex.
- *   _cupsThreadCreate() - Create a thread.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
 
 
 #if defined(HAVE_PTHREAD_H)
+/*
+ * '_cupsMutexInit()' - Initialize a mutex.
+ */
+
+void
+_cupsMutexInit(_cups_mutex_t *mutex)   /* I - Mutex */
+{
+  pthread_mutex_init(mutex, NULL);
+}
+
+
 /*
  * '_cupsMutexLock()' - Lock a mutex.
  */
@@ -49,11 +56,55 @@ _cupsMutexUnlock(_cups_mutex_t *mutex)      /* I - Mutex */
 }
 
 
+/*
+ * '_cupsRWInit()' - Initialize a reader/writer lock.
+ */
+
+void
+_cupsRWInit(_cups_rwlock_t *rwlock)    /* I - Reader/writer lock */
+{
+  pthread_rwlock_init(rwlock, NULL);
+}
+
+
+/*
+ * '_cupsRWLockRead()' - Acquire a reader/writer lock for reading.
+ */
+
+void
+_cupsRWLockRead(_cups_rwlock_t *rwlock)        /* I - Reader/writer lock */
+{
+  pthread_rwlock_rdlock(rwlock);
+}
+
+
+/*
+ * '_cupsRWLockWrite()' - Acquire a reader/writer lock for writing.
+ */
+
+void
+_cupsRWLockWrite(_cups_rwlock_t *rwlock)/* I - Reader/writer lock */
+{
+  pthread_rwlock_wrlock(rwlock);
+}
+
+
+/*
+ * '_cupsRWUnlock()' - Release a reader/writer lock.
+ */
+
+void
+_cupsRWUnlock(_cups_rwlock_t *rwlock)  /* I - Reader/writer lock */
+{
+  pthread_rwlock_unlock(rwlock);
+}
+
+
 /*
  * '_cupsThreadCreate()' - Create a thread.
  */
 
-int                                    /* O - 0 on failure, 1 on success */    
+int                                    /* O - 0 on failure, 1 on success */
 _cupsThreadCreate(
     _cups_thread_func_t func,          /* I - Entry point */
     void                *arg)          /* I - Entry point context */
@@ -68,6 +119,18 @@ _cupsThreadCreate(
 #  include <process.h>
 
 
+/*
+ * '_cupsMutexInit()' - Initialize a mutex.
+ */
+
+void
+_cupsMutexInit(_cups_mutex_t *mutex)   /* I - Mutex */
+{
+  InitializeCriticalSection(&mutex->m_criticalSection);
+  mutex->m_init = 1;
+}
+
+
 /*
  * '_cupsMutexLock()' - Lock a mutex.
  */
@@ -103,11 +166,55 @@ _cupsMutexUnlock(_cups_mutex_t *mutex)    /* I - Mutex */
 }
 
 
+/*
+ * '_cupsRWInit()' - Initialize a reader/writer lock.
+ */
+
+void
+_cupsRWInit(_cups_rwlock_t *rwlock)    /* I - Reader/writer lock */
+{
+  _cupsMutexInit((_cups_mutex_t *)rwlock);
+}
+
+
+/*
+ * '_cupsRWLockRead()' - Acquire a reader/writer lock for reading.
+ */
+
+void
+_cupsRWLockRead(_cups_rwlock_t *rwlock)        /* I - Reader/writer lock */
+{
+  _cupsMutexLock((_cups_mutex_t *)rwlock);
+}
+
+
+/*
+ * '_cupsRWLockWrite()' - Acquire a reader/writer lock for writing.
+ */
+
+void
+_cupsRWLockWrite(_cups_rwlock_t *rwlock)/* I - Reader/writer lock */
+{
+  _cupsMutexLock((_cups_mutex_t *)rwlock);
+}
+
+
+/*
+ * '_cupsRWUnlock()' - Release a reader/writer lock.
+ */
+
+void
+_cupsRWUnlock(_cups_rwlock_t *rwlock)  /* I - Reader/writer lock */
+{
+  _cupsMutexUnlock((_cups_mutex_t *)rwlock);
+}
+
+
 /*
  * '_cupsThreadCreate()' - Create a thread.
  */
 
-int                                    /* O - 0 on failure, 1 on success */    
+int                                    /* O - 0 on failure, 1 on success */
 _cupsThreadCreate(
     _cups_thread_func_t func,          /* I - Entry point */
     void                *arg)          /* I - Entry point context */
@@ -118,6 +225,17 @@ _cupsThreadCreate(
 
 
 #else
+/*
+ * '_cupsMutexInit()' - Initialize a mutex.
+ */
+
+void
+_cupsMutexInit(_cups_mutex_t *mutex)   /* I - Mutex */
+{
+  (void)mutex;
+}
+
+
 /*
  * '_cupsMutexLock()' - Lock a mutex.
  */
@@ -125,6 +243,7 @@ _cupsThreadCreate(
 void
 _cupsMutexLock(_cups_mutex_t *mutex)   /* I - Mutex */
 {
+  (void)mutex;
 }
 
 
@@ -135,10 +254,74 @@ _cupsMutexLock(_cups_mutex_t *mutex)      /* I - Mutex */
 void
 _cupsMutexUnlock(_cups_mutex_t *mutex) /* I - Mutex */
 {
+  (void)mutex;
+}
+
+
+/*
+ * '_cupsRWInit()' - Initialize a reader/writer lock.
+ */
+
+void
+_cupsRWInit(_cups_rwlock_t *rwlock)    /* I - Reader/writer lock */
+{
+  (void)rwlock;
+}
+
+
+/*
+ * '_cupsRWLockRead()' - Acquire a reader/writer lock for reading.
+ */
+
+void
+_cupsRWLockRead(_cups_rwlock_t *rwlock)        /* I - Reader/writer lock */
+{
+  (void)rwlock;
+}
+
+
+/*
+ * '_cupsRWLockWrite()' - Acquire a reader/writer lock for writing.
+ */
+
+void
+_cupsRWLockWrite(_cups_rwlock_t *rwlock)/* I - Reader/writer lock */
+{
+  (void)rwlock;
+}
+
+
+/*
+ * '_cupsRWUnlock()' - Release a reader/writer lock.
+ */
+
+void
+_cupsRWUnlock(_cups_rwlock_t *rwlock)  /* I - Reader/writer lock */
+{
+  (void)rwlock;
+}
+
+
+/*
+ * '_cupsThreadCreate()' - Create a thread.
+ */
+
+int                                    /* O - 0 on failure, 1 on success */
+_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);
+
+  (void)func;
+  (void)arg;
+
+  return (0);
 }
 #endif /* HAVE_PTHREAD_H */
 
 
 /*
- * End of "$Id$".
+ * End of "$Id: thread.c 11984 2014-07-02 13:16:59Z msweet $".
  */