• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #  include <cups/versioning.h>
18 
19 
20 /*
21  * C++ magic...
22  */
23 
24 #  ifdef __cplusplus
25 extern "C" {
26 #  endif /* __cplusplus */
27 
28 
29 #  ifdef HAVE_PTHREAD_H			/* POSIX threading */
30 #    include <pthread.h>
31 typedef void *(*_cups_thread_func_t)(void *arg);
32 typedef pthread_t _cups_thread_t;
33 typedef pthread_cond_t _cups_cond_t;
34 typedef pthread_mutex_t _cups_mutex_t;
35 typedef pthread_rwlock_t _cups_rwlock_t;
36 typedef pthread_key_t	_cups_threadkey_t;
37 #    define _CUPS_COND_INITIALIZER PTHREAD_COND_INITIALIZER
38 #    define _CUPS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
39 #    define _CUPS_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
40 #    define _CUPS_THREADKEY_INITIALIZER 0
41 #    define _cupsThreadGetData(k) pthread_getspecific(k)
42 #    define _cupsThreadSetData(k,p) pthread_setspecific(k,p)
43 
44 #  elif defined(_WIN32)			/* Windows threading */
45 #    include <winsock2.h>
46 #    include <windows.h>
47 typedef void *(__stdcall *_cups_thread_func_t)(void *arg);
48 typedef int _cups_thread_t;
49 typedef char _cups_cond_t;		/* TODO: Implement Win32 conditional */
50 typedef struct _cups_mutex_s
51 {
52   int			m_init;		/* Flag for on-demand initialization */
53   CRITICAL_SECTION	m_criticalSection;
54 					/* Win32 Critical Section */
55 } _cups_mutex_t;
56 typedef _cups_mutex_t _cups_rwlock_t;	/* TODO: Implement Win32 reader/writer lock */
57 typedef DWORD	_cups_threadkey_t;
58 #    define _CUPS_COND_INITIALIZER 0
59 #    define _CUPS_MUTEX_INITIALIZER { 0, 0 }
60 #    define _CUPS_RWLOCK_INITIALIZER { 0, 0 }
61 #    define _CUPS_THREADKEY_INITIALIZER 0
62 #    define _cupsThreadGetData(k) TlsGetValue(k)
63 #    define _cupsThreadSetData(k,p) TlsSetValue(k,p)
64 
65 #  else					/* No threading */
66 typedef void	*(*_cups_thread_func_t)(void *arg);
67 typedef int	_cups_thread_t;
68 typedef char	_cups_cond_t;
69 typedef char	_cups_mutex_t;
70 typedef char	_cups_rwlock_t;
71 typedef void	*_cups_threadkey_t;
72 #    define _CUPS_COND_INITIALIZER 0
73 #    define _CUPS_MUTEX_INITIALIZER 0
74 #    define _CUPS_RWLOCK_INITIALIZER 0
75 #    define _CUPS_THREADKEY_INITIALIZER (void *)0
76 #    define _cupsThreadGetData(k) k
77 #    define _cupsThreadSetData(k,p) k=p
78 #  endif /* HAVE_PTHREAD_H */
79 
80 
81 /*
82  * Functions...
83  */
84 
85 extern void	_cupsCondBroadcast(_cups_cond_t *cond) _CUPS_PRIVATE;
86 extern void	_cupsCondInit(_cups_cond_t *cond) _CUPS_PRIVATE;
87 extern void	_cupsCondWait(_cups_cond_t *cond, _cups_mutex_t *mutex, double timeout) _CUPS_PRIVATE;
88 extern void	_cupsMutexInit(_cups_mutex_t *mutex) _CUPS_PRIVATE;
89 extern void	_cupsMutexLock(_cups_mutex_t *mutex) _CUPS_PRIVATE;
90 extern void	_cupsMutexUnlock(_cups_mutex_t *mutex) _CUPS_PRIVATE;
91 extern void	_cupsRWInit(_cups_rwlock_t *rwlock) _CUPS_PRIVATE;
92 extern void	_cupsRWLockRead(_cups_rwlock_t *rwlock) _CUPS_PRIVATE;
93 extern void	_cupsRWLockWrite(_cups_rwlock_t *rwlock) _CUPS_PRIVATE;
94 extern void	_cupsRWUnlock(_cups_rwlock_t *rwlock) _CUPS_PRIVATE;
95 extern void	_cupsThreadCancel(_cups_thread_t thread) _CUPS_PRIVATE;
96 extern _cups_thread_t _cupsThreadCreate(_cups_thread_func_t func, void *arg) _CUPS_PRIVATE;
97 extern void     _cupsThreadDetach(_cups_thread_t thread) _CUPS_PRIVATE;
98 extern void	*_cupsThreadWait(_cups_thread_t thread) _CUPS_PRIVATE;
99 
100 #  ifdef __cplusplus
101 }
102 #  endif /* __cplusplus */
103 #endif /* !_CUPS_THREAD_PRIVATE_H_ */
104