]>
Commit | Line | Data |
---|---|---|
c7017ecc | 1 | /* |
7e86f2f6 | 2 | * Private threading definitions for CUPS. |
c7017ecc | 3 | * |
b908d72c | 4 | * Copyright 2009-2017 by Apple Inc. |
c7017ecc | 5 | * |
7e86f2f6 MS |
6 | * These coded instructions, statements, and computer programs are the |
7 | * property of Apple Inc. and are protected by Federal copyright | |
8 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
9 | * which should have been included with this file. If this file is | |
57b7b66b | 10 | * missing or damaged, see the license at "http://www.cups.org/". |
6539a0af MS |
11 | * |
12 | * This file is subject to the Apple OS-Developed Software exception. | |
c7017ecc MS |
13 | */ |
14 | ||
15 | #ifndef _CUPS_THREAD_PRIVATE_H_ | |
16 | # define _CUPS_THREAD_PRIVATE_H_ | |
17 | ||
18 | /* | |
19 | * Include necessary headers... | |
20 | */ | |
21 | ||
22 | # include "config.h" | |
23 | ||
24 | ||
25 | /* | |
26 | * C++ magic... | |
27 | */ | |
28 | ||
29 | # ifdef __cplusplus | |
30 | extern "C" { | |
31 | # endif /* __cplusplus */ | |
32 | ||
33 | ||
ad7daa25 | 34 | # ifdef HAVE_PTHREAD_H /* POSIX threading */ |
c7017ecc MS |
35 | # include <pthread.h> |
36 | typedef void *(*_cups_thread_func_t)(void *arg); | |
ad7daa25 MS |
37 | typedef pthread_t _cups_thread_t; |
38 | typedef pthread_cond_t _cups_cond_t; | |
c7017ecc | 39 | typedef pthread_mutex_t _cups_mutex_t; |
1106b00e | 40 | typedef pthread_rwlock_t _cups_rwlock_t; |
c7017ecc | 41 | typedef pthread_key_t _cups_threadkey_t; |
ad7daa25 | 42 | # define _CUPS_COND_INITIALIZER PTHREAD_COND_INITIALIZER |
c7017ecc | 43 | # define _CUPS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER |
1106b00e | 44 | # define _CUPS_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER |
7e86f2f6 | 45 | # define _CUPS_THREADKEY_INITIALIZER 0 |
c7017ecc MS |
46 | # define _cupsThreadGetData(k) pthread_getspecific(k) |
47 | # define _cupsThreadSetData(k,p) pthread_setspecific(k,p) | |
48 | ||
ad7daa25 | 49 | # elif defined(WIN32) /* Windows threading */ |
c7017ecc MS |
50 | # include <winsock2.h> |
51 | # include <windows.h> | |
52 | typedef void *(__stdcall *_cups_thread_func_t)(void *arg); | |
ad7daa25 MS |
53 | typedef int _cups_thread_t; |
54 | typedef char _cups_cond_t; /* TODO: Implement Win32 conditional */ | |
c7017ecc MS |
55 | typedef struct _cups_mutex_s |
56 | { | |
f3c17241 | 57 | int m_init; /* Flag for on-demand initialization */ |
c7017ecc MS |
58 | CRITICAL_SECTION m_criticalSection; |
59 | /* Win32 Critical Section */ | |
60 | } _cups_mutex_t; | |
1106b00e | 61 | typedef _cups_mutex_t _cups_rwlock_t; /* TODO: Implement Win32 reader/writer lock */ |
c7017ecc | 62 | typedef DWORD _cups_threadkey_t; |
ad7daa25 | 63 | # define _CUPS_COND_INITIALIZER 0 |
c7017ecc | 64 | # define _CUPS_MUTEX_INITIALIZER { 0, 0 } |
1106b00e | 65 | # define _CUPS_RWLOCK_INITIALIZER { 0, 0 } |
c7017ecc MS |
66 | # define _CUPS_THREADKEY_INITIALIZER 0 |
67 | # define _cupsThreadGetData(k) TlsGetValue(k) | |
68 | # define _cupsThreadSetData(k,p) TlsSetValue(k,p) | |
69 | ||
ad7daa25 | 70 | # else /* No threading */ |
f3c17241 | 71 | typedef void *(*_cups_thread_func_t)(void *arg); |
ad7daa25 MS |
72 | typedef int _cups_thread_t; |
73 | typedef char _cups_cond_t; | |
c7017ecc | 74 | typedef char _cups_mutex_t; |
1106b00e | 75 | typedef char _cups_rwlock_t; |
c7017ecc | 76 | typedef void *_cups_threadkey_t; |
ad7daa25 | 77 | # define _CUPS_COND_INITIALIZER 0 |
c7017ecc | 78 | # define _CUPS_MUTEX_INITIALIZER 0 |
1106b00e | 79 | # define _CUPS_RWLOCK_INITIALIZER 0 |
c7017ecc MS |
80 | # define _CUPS_THREADKEY_INITIALIZER (void *)0 |
81 | # define _cupsThreadGetData(k) k | |
82 | # define _cupsThreadSetData(k,p) k=p | |
83 | # endif /* HAVE_PTHREAD_H */ | |
84 | ||
85 | ||
86 | /* | |
87 | * Functions... | |
88 | */ | |
89 | ||
ad7daa25 MS |
90 | extern void _cupsCondBroadcast(_cups_cond_t *cond); |
91 | extern void _cupsCondInit(_cups_cond_t *cond); | |
92 | extern void _cupsCondWait(_cups_cond_t *cond, _cups_mutex_t *mutex, double timeout); | |
1106b00e | 93 | extern void _cupsMutexInit(_cups_mutex_t *mutex); |
c7017ecc MS |
94 | extern void _cupsMutexLock(_cups_mutex_t *mutex); |
95 | extern void _cupsMutexUnlock(_cups_mutex_t *mutex); | |
1106b00e MS |
96 | extern void _cupsRWInit(_cups_rwlock_t *rwlock); |
97 | extern void _cupsRWLockRead(_cups_rwlock_t *rwlock); | |
98 | extern void _cupsRWLockWrite(_cups_rwlock_t *rwlock); | |
99 | extern void _cupsRWUnlock(_cups_rwlock_t *rwlock); | |
ad7daa25 MS |
100 | extern void _cupsThreadCancel(_cups_thread_t thread); |
101 | extern _cups_thread_t _cupsThreadCreate(_cups_thread_func_t func, void *arg); | |
b908d72c | 102 | extern void _cupsThreadDetach(_cups_thread_t thread); |
ad7daa25 | 103 | extern void *_cupsThreadWait(_cups_thread_t thread); |
c7017ecc MS |
104 | |
105 | # ifdef __cplusplus | |
106 | } | |
107 | # endif /* __cplusplus */ | |
108 | #endif /* !_CUPS_THREAD_PRIVATE_H_ */ |