]>
Commit | Line | Data |
---|---|---|
c7017ecc | 1 | /* |
7e86f2f6 | 2 | * Private threading definitions for CUPS. |
c7017ecc | 3 | * |
7e86f2f6 | 4 | * Copyright 2009-2014 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 | |
10 | * file is 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 | ||
34 | # ifdef HAVE_PTHREAD_H | |
35 | # include <pthread.h> | |
36 | typedef void *(*_cups_thread_func_t)(void *arg); | |
37 | typedef pthread_mutex_t _cups_mutex_t; | |
1106b00e | 38 | typedef pthread_rwlock_t _cups_rwlock_t; |
c7017ecc MS |
39 | typedef pthread_key_t _cups_threadkey_t; |
40 | # define _CUPS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER | |
1106b00e | 41 | # define _CUPS_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER |
7e86f2f6 | 42 | # define _CUPS_THREADKEY_INITIALIZER 0 |
c7017ecc MS |
43 | # define _cupsThreadGetData(k) pthread_getspecific(k) |
44 | # define _cupsThreadSetData(k,p) pthread_setspecific(k,p) | |
45 | ||
46 | # elif defined(WIN32) | |
47 | # include <winsock2.h> | |
48 | # include <windows.h> | |
49 | typedef void *(__stdcall *_cups_thread_func_t)(void *arg); | |
50 | typedef struct _cups_mutex_s | |
51 | { | |
f3c17241 | 52 | int m_init; /* Flag for on-demand initialization */ |
c7017ecc MS |
53 | CRITICAL_SECTION m_criticalSection; |
54 | /* Win32 Critical Section */ | |
55 | } _cups_mutex_t; | |
1106b00e | 56 | typedef _cups_mutex_t _cups_rwlock_t; /* TODO: Implement Win32 reader/writer lock */ |
c7017ecc MS |
57 | typedef DWORD _cups_threadkey_t; |
58 | # define _CUPS_MUTEX_INITIALIZER { 0, 0 } | |
1106b00e | 59 | # define _CUPS_RWLOCK_INITIALIZER { 0, 0 } |
c7017ecc MS |
60 | # define _CUPS_THREADKEY_INITIALIZER 0 |
61 | # define _cupsThreadGetData(k) TlsGetValue(k) | |
62 | # define _cupsThreadSetData(k,p) TlsSetValue(k,p) | |
63 | ||
64 | # else | |
f3c17241 | 65 | typedef void *(*_cups_thread_func_t)(void *arg); |
c7017ecc | 66 | typedef char _cups_mutex_t; |
1106b00e | 67 | typedef char _cups_rwlock_t; |
c7017ecc MS |
68 | typedef void *_cups_threadkey_t; |
69 | # define _CUPS_MUTEX_INITIALIZER 0 | |
1106b00e | 70 | # define _CUPS_RWLOCK_INITIALIZER 0 |
c7017ecc MS |
71 | # define _CUPS_THREADKEY_INITIALIZER (void *)0 |
72 | # define _cupsThreadGetData(k) k | |
73 | # define _cupsThreadSetData(k,p) k=p | |
74 | # endif /* HAVE_PTHREAD_H */ | |
75 | ||
76 | ||
77 | /* | |
78 | * Functions... | |
79 | */ | |
80 | ||
1106b00e | 81 | extern void _cupsMutexInit(_cups_mutex_t *mutex); |
c7017ecc MS |
82 | extern void _cupsMutexLock(_cups_mutex_t *mutex); |
83 | extern void _cupsMutexUnlock(_cups_mutex_t *mutex); | |
1106b00e MS |
84 | extern void _cupsRWInit(_cups_rwlock_t *rwlock); |
85 | extern void _cupsRWLockRead(_cups_rwlock_t *rwlock); | |
86 | extern void _cupsRWLockWrite(_cups_rwlock_t *rwlock); | |
87 | extern void _cupsRWUnlock(_cups_rwlock_t *rwlock); | |
c7017ecc MS |
88 | extern int _cupsThreadCreate(_cups_thread_func_t func, void *arg); |
89 | ||
90 | ||
91 | # ifdef __cplusplus | |
92 | } | |
93 | # endif /* __cplusplus */ | |
94 | #endif /* !_CUPS_THREAD_PRIVATE_H_ */ |