• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Private threading definitions for CUPS.
3  *
4  * Copyright 2009-2017 by Apple Inc.
5  *
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/".
11  *
12  * This file is subject to the Apple OS-Developed Software exception.
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			/* POSIX threading */
35 #    include <pthread.h>
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)
48 
49 #  elif defined(_WIN32)			/* Windows threading */
50 #    include <winsock2.h>
51 #    include <windows.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
56 {
57   int			m_init;		/* Flag for on-demand initialization */
58   CRITICAL_SECTION	m_criticalSection;
59 					/* Win32 Critical Section */
60 } _cups_mutex_t;
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)
69 
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 */
84 
85 
86 /*
87  * Functions...
88  */
89 
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);
104 
105 #  ifdef __cplusplus
106 }
107 #  endif /* __cplusplus */
108 #endif /* !_CUPS_THREAD_PRIVATE_H_ */
109