2 * Private threading definitions for CUPS.
4 * Copyright 2009-2017 by Apple Inc.
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 * missing or damaged, see the license at "http://www.cups.org/".
12 * This file is subject to the Apple OS-Developed Software exception.
15 #ifndef _CUPS_THREAD_PRIVATE_H_
16 # define _CUPS_THREAD_PRIVATE_H_
19 * Include necessary headers...
31 # endif /* __cplusplus */
34 # ifdef HAVE_PTHREAD_H /* POSIX threading */
36 typedef void *(*_cups_thread_func_t
)(void *arg
);
37 typedef pthread_t _cups_thread_t
;
38 typedef pthread_cond_t _cups_cond_t
;
39 typedef pthread_mutex_t _cups_mutex_t
;
40 typedef pthread_rwlock_t _cups_rwlock_t
;
41 typedef pthread_key_t _cups_threadkey_t
;
42 # define _CUPS_COND_INITIALIZER PTHREAD_COND_INITIALIZER
43 # define _CUPS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
44 # define _CUPS_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
45 # define _CUPS_THREADKEY_INITIALIZER 0
46 # define _cupsThreadGetData(k) pthread_getspecific(k)
47 # define _cupsThreadSetData(k,p) pthread_setspecific(k,p)
49 # elif defined(WIN32) /* Windows threading */
50 # include <winsock2.h>
52 typedef void *(__stdcall
*_cups_thread_func_t
)(void *arg
);
53 typedef int _cups_thread_t
;
54 typedef char _cups_cond_t
; /* TODO: Implement Win32 conditional */
55 typedef struct _cups_mutex_s
57 int m_init
; /* Flag for on-demand initialization */
58 CRITICAL_SECTION m_criticalSection
;
59 /* Win32 Critical Section */
61 typedef _cups_mutex_t _cups_rwlock_t
; /* TODO: Implement Win32 reader/writer lock */
62 typedef DWORD _cups_threadkey_t
;
63 # define _CUPS_COND_INITIALIZER 0
64 # define _CUPS_MUTEX_INITIALIZER { 0, 0 }
65 # define _CUPS_RWLOCK_INITIALIZER { 0, 0 }
66 # define _CUPS_THREADKEY_INITIALIZER 0
67 # define _cupsThreadGetData(k) TlsGetValue(k)
68 # define _cupsThreadSetData(k,p) TlsSetValue(k,p)
70 # else /* No threading */
71 typedef void *(*_cups_thread_func_t
)(void *arg
);
72 typedef int _cups_thread_t
;
73 typedef char _cups_cond_t
;
74 typedef char _cups_mutex_t
;
75 typedef char _cups_rwlock_t
;
76 typedef void *_cups_threadkey_t
;
77 # define _CUPS_COND_INITIALIZER 0
78 # define _CUPS_MUTEX_INITIALIZER 0
79 # define _CUPS_RWLOCK_INITIALIZER 0
80 # define _CUPS_THREADKEY_INITIALIZER (void *)0
81 # define _cupsThreadGetData(k) k
82 # define _cupsThreadSetData(k,p) k=p
83 # endif /* HAVE_PTHREAD_H */
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
);
93 extern void _cupsMutexInit(_cups_mutex_t
*mutex
);
94 extern void _cupsMutexLock(_cups_mutex_t
*mutex
);
95 extern void _cupsMutexUnlock(_cups_mutex_t
*mutex
);
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
);
100 extern void _cupsThreadCancel(_cups_thread_t thread
);
101 extern _cups_thread_t
_cupsThreadCreate(_cups_thread_func_t func
, void *arg
);
102 extern void _cupsThreadDetach(_cups_thread_t thread
);
103 extern void *_cupsThreadWait(_cups_thread_t thread
);
107 # endif /* __cplusplus */
108 #endif /* !_CUPS_THREAD_PRIVATE_H_ */