]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/thread.c
2 * "$Id: thread.c 11627 2014-02-20 16:15:09Z msweet $"
4 * Threading primitives for CUPS.
6 * Copyright 2009-2014 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
14 * This file is subject to the Apple OS-Developed Software exception.
18 * Include necessary headers...
21 #include "cups-private.h"
22 #include "thread-private.h"
25 #if defined(HAVE_PTHREAD_H)
27 * '_cupsMutexInit()' - Initialize a mutex.
31 _cupsMutexInit(_cups_mutex_t
*mutex
) /* I - Mutex */
33 pthread_mutex_init(mutex
, NULL
);
38 * '_cupsMutexLock()' - Lock a mutex.
42 _cupsMutexLock(_cups_mutex_t
*mutex
) /* I - Mutex */
44 pthread_mutex_lock(mutex
);
49 * '_cupsMutexUnlock()' - Unlock a mutex.
53 _cupsMutexUnlock(_cups_mutex_t
*mutex
) /* I - Mutex */
55 pthread_mutex_unlock(mutex
);
60 * '_cupsRWInit()' - Initialize a reader/writer lock.
64 _cupsRWInit(_cups_rwlock_t
*rwlock
) /* I - Reader/writer lock */
66 pthread_rwlock_init(rwlock
, NULL
);
71 * '_cupsRWLockRead()' - Acquire a reader/writer lock for reading.
75 _cupsRWLockRead(_cups_rwlock_t
*rwlock
) /* I - Reader/writer lock */
77 pthread_rwlock_rdlock(rwlock
);
82 * '_cupsRWLockWrite()' - Acquire a reader/writer lock for writing.
86 _cupsRWLockWrite(_cups_rwlock_t
*rwlock
)/* I - Reader/writer lock */
88 pthread_rwlock_wrlock(rwlock
);
93 * '_cupsRWUnlock()' - Release a reader/writer lock.
97 _cupsRWUnlock(_cups_rwlock_t
*rwlock
) /* I - Reader/writer lock */
99 pthread_rwlock_unlock(rwlock
);
104 * '_cupsThreadCreate()' - Create a thread.
107 int /* O - 0 on failure, 1 on success */
109 _cups_thread_func_t func
, /* I - Entry point */
110 void *arg
) /* I - Entry point context */
114 return (pthread_create(&thread
, NULL
, (void *(*)(void *))func
, arg
) == 0);
119 # include <process.h>
123 * '_cupsMutexInit()' - Initialize a mutex.
127 _cupsMutexInit(_cups_mutex_t
*mutex
) /* I - Mutex */
129 InitializeCriticalSection(&mutex
->m_criticalSection
);
135 * '_cupsMutexLock()' - Lock a mutex.
139 _cupsMutexLock(_cups_mutex_t
*mutex
) /* I - Mutex */
147 InitializeCriticalSection(&mutex
->m_criticalSection
);
154 EnterCriticalSection(&mutex
->m_criticalSection
);
159 * '_cupsMutexUnlock()' - Unlock a mutex.
163 _cupsMutexUnlock(_cups_mutex_t
*mutex
) /* I - Mutex */
165 LeaveCriticalSection(&mutex
->m_criticalSection
);
170 * '_cupsRWInit()' - Initialize a reader/writer lock.
174 _cupsRWInit(_cups_rwlock_t
*rwlock
) /* I - Reader/writer lock */
176 _cupsMutexInit((_cups_mutex_t
*)rwlock
);
181 * '_cupsRWLockRead()' - Acquire a reader/writer lock for reading.
185 _cupsRWLockRead(_cups_rwlock_t
*rwlock
) /* I - Reader/writer lock */
187 _cupsMutexLock((_cups_mutex_t
*)rwlock
);
192 * '_cupsRWLockWrite()' - Acquire a reader/writer lock for writing.
196 _cupsRWLockWrite(_cups_rwlock_t
*rwlock
)/* I - Reader/writer lock */
198 _cupsMutexLock((_cups_mutex_t
*)rwlock
);
203 * '_cupsRWUnlock()' - Release a reader/writer lock.
207 _cupsRWUnlock(_cups_rwlock_t
*rwlock
) /* I - Reader/writer lock */
209 _cupsMutexUnlock((_cups_mutex_t
*)rwlock
);
214 * '_cupsThreadCreate()' - Create a thread.
217 int /* O - 0 on failure, 1 on success */
219 _cups_thread_func_t func
, /* I - Entry point */
220 void *arg
) /* I - Entry point context */
222 return (_beginthreadex(NULL
, 0, (LPTHREAD_START_ROUTINE
) func
, arg
, 0, NULL
)
229 * '_cupsMutexInit()' - Initialize a mutex.
233 _cupsMutexInit(_cups_mutex_t
*mutex
) /* I - Mutex */
240 * '_cupsMutexLock()' - Lock a mutex.
244 _cupsMutexLock(_cups_mutex_t
*mutex
) /* I - Mutex */
251 * '_cupsMutexUnlock()' - Unlock a mutex.
255 _cupsMutexUnlock(_cups_mutex_t
*mutex
) /* I - Mutex */
262 * '_cupsRWInit()' - Initialize a reader/writer lock.
266 _cupsRWInit(_cups_rwlock_t
*rwlock
) /* I - Reader/writer lock */
273 * '_cupsRWLockRead()' - Acquire a reader/writer lock for reading.
277 _cupsRWLockRead(_cups_rwlock_t
*rwlock
) /* I - Reader/writer lock */
284 * '_cupsRWLockWrite()' - Acquire a reader/writer lock for writing.
288 _cupsRWLockWrite(_cups_rwlock_t
*rwlock
)/* I - Reader/writer lock */
295 * '_cupsRWUnlock()' - Release a reader/writer lock.
299 _cupsRWUnlock(_cups_rwlock_t
*rwlock
) /* I - Reader/writer lock */
306 * '_cupsThreadCreate()' - Create a thread.
309 int /* O - 0 on failure, 1 on success */
311 _cups_thread_func_t func
, /* I - Entry point */
312 void *arg
) /* I - Entry point context */
314 fputs("DEBUG: CUPS was compiled without threading support, no thread "
315 "created.\n", stderr
);
322 #endif /* HAVE_PTHREAD_H */
326 * End of "$Id: thread.c 11627 2014-02-20 16:15:09Z msweet $".