]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/thread-private.h
08e669c8eb29278f790f700e51935677a1f99db8
[thirdparty/cups.git] / cups / thread-private.h
1 /*
2 * Private threading definitions for CUPS.
3 *
4 * Copyright 2009-2017 by Apple Inc.
5 *
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
7 */
8
9 #ifndef _CUPS_THREAD_PRIVATE_H_
10 # define _CUPS_THREAD_PRIVATE_H_
11
12 /*
13 * Include necessary headers...
14 */
15
16 # include "config.h"
17
18
19 /*
20 * C++ magic...
21 */
22
23 # ifdef __cplusplus
24 extern "C" {
25 # endif /* __cplusplus */
26
27
28 # ifdef HAVE_PTHREAD_H /* POSIX threading */
29 # include <pthread.h>
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)
42
43 # elif defined(WIN32) /* Windows threading */
44 # include <winsock2.h>
45 # include <windows.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
50 {
51 int m_init; /* Flag for on-demand initialization */
52 CRITICAL_SECTION m_criticalSection;
53 /* Win32 Critical Section */
54 } _cups_mutex_t;
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)
63
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 */
78
79
80 /*
81 * Functions...
82 */
83
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);
98
99 # ifdef __cplusplus
100 }
101 # endif /* __cplusplus */
102 #endif /* !_CUPS_THREAD_PRIVATE_H_ */