2 * Private threading definitions for CUPS.
4 * Copyright 2009-2017 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
9 #ifndef _CUPS_THREAD_PRIVATE_H_
10 # define _CUPS_THREAD_PRIVATE_H_
13 * Include necessary headers...
25 # endif /* __cplusplus */
28 # ifdef HAVE_PTHREAD_H /* POSIX threading */
30 typedef void *(*_cups_thread_func_t
)(void *arg
);
31 typedef pthread_t _cups_thread_t
;
32 typedef pthread_cond_t _cups_cond_t
;
33 typedef pthread_mutex_t _cups_mutex_t
;
34 typedef pthread_rwlock_t _cups_rwlock_t
;
35 typedef pthread_key_t _cups_threadkey_t
;
36 # define _CUPS_COND_INITIALIZER PTHREAD_COND_INITIALIZER
37 # define _CUPS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
38 # define _CUPS_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
39 # define _CUPS_THREADKEY_INITIALIZER 0
40 # define _cupsThreadGetData(k) pthread_getspecific(k)
41 # define _cupsThreadSetData(k,p) pthread_setspecific(k,p)
43 # elif defined(WIN32) /* Windows threading */
44 # include <winsock2.h>
46 typedef void *(__stdcall
*_cups_thread_func_t
)(void *arg
);
47 typedef int _cups_thread_t
;
48 typedef char _cups_cond_t
; /* TODO: Implement Win32 conditional */
49 typedef struct _cups_mutex_s
51 int m_init
; /* Flag for on-demand initialization */
52 CRITICAL_SECTION m_criticalSection
;
53 /* Win32 Critical Section */
55 typedef _cups_mutex_t _cups_rwlock_t
; /* TODO: Implement Win32 reader/writer lock */
56 typedef DWORD _cups_threadkey_t
;
57 # define _CUPS_COND_INITIALIZER 0
58 # define _CUPS_MUTEX_INITIALIZER { 0, 0 }
59 # define _CUPS_RWLOCK_INITIALIZER { 0, 0 }
60 # define _CUPS_THREADKEY_INITIALIZER 0
61 # define _cupsThreadGetData(k) TlsGetValue(k)
62 # define _cupsThreadSetData(k,p) TlsSetValue(k,p)
64 # else /* No threading */
65 typedef void *(*_cups_thread_func_t
)(void *arg
);
66 typedef int _cups_thread_t
;
67 typedef char _cups_cond_t
;
68 typedef char _cups_mutex_t
;
69 typedef char _cups_rwlock_t
;
70 typedef void *_cups_threadkey_t
;
71 # define _CUPS_COND_INITIALIZER 0
72 # define _CUPS_MUTEX_INITIALIZER 0
73 # define _CUPS_RWLOCK_INITIALIZER 0
74 # define _CUPS_THREADKEY_INITIALIZER (void *)0
75 # define _cupsThreadGetData(k) k
76 # define _cupsThreadSetData(k,p) k=p
77 # endif /* HAVE_PTHREAD_H */
84 extern void _cupsCondBroadcast(_cups_cond_t
*cond
);
85 extern void _cupsCondInit(_cups_cond_t
*cond
);
86 extern void _cupsCondWait(_cups_cond_t
*cond
, _cups_mutex_t
*mutex
, double timeout
);
87 extern void _cupsMutexInit(_cups_mutex_t
*mutex
);
88 extern void _cupsMutexLock(_cups_mutex_t
*mutex
);
89 extern void _cupsMutexUnlock(_cups_mutex_t
*mutex
);
90 extern void _cupsRWInit(_cups_rwlock_t
*rwlock
);
91 extern void _cupsRWLockRead(_cups_rwlock_t
*rwlock
);
92 extern void _cupsRWLockWrite(_cups_rwlock_t
*rwlock
);
93 extern void _cupsRWUnlock(_cups_rwlock_t
*rwlock
);
94 extern void _cupsThreadCancel(_cups_thread_t thread
);
95 extern _cups_thread_t
_cupsThreadCreate(_cups_thread_func_t func
, void *arg
);
96 extern void _cupsThreadDetach(_cups_thread_t thread
);
97 extern void *_cupsThreadWait(_cups_thread_t thread
);
101 # endif /* __cplusplus */
102 #endif /* !_CUPS_THREAD_PRIVATE_H_ */