4 * Private threading definitions for CUPS.
6 * Copyright 2009-2010 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
15 #ifndef _CUPS_THREAD_PRIVATE_H_
16 # define _CUPS_THREAD_PRIVATE_H_
19 * Include necessary headers...
31 # endif /* __cplusplus */
34 # ifdef HAVE_PTHREAD_H
36 typedef void *(*_cups_thread_func_t
)(void *arg
);
37 typedef pthread_mutex_t _cups_mutex_t
;
38 typedef pthread_rwlock_t _cups_rwlock_t
;
39 typedef pthread_key_t _cups_threadkey_t
;
40 # define _CUPS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
41 # define _CUPS_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
42 # define _CUPS_THREADKEY_INITIALIZER -1
43 # define _cupsThreadGetData(k) pthread_getspecific(k)
44 # define _cupsThreadSetData(k,p) pthread_setspecific(k,p)
47 # include <winsock2.h>
49 typedef void *(__stdcall
*_cups_thread_func_t
)(void *arg
);
50 typedef struct _cups_mutex_s
52 int m_init
; /* Flag for on-demand initialization */
53 CRITICAL_SECTION m_criticalSection
;
54 /* Win32 Critical Section */
56 typedef _cups_mutex_t _cups_rwlock_t
; /* TODO: Implement Win32 reader/writer lock */
57 typedef DWORD _cups_threadkey_t
;
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)
65 typedef char _cups_mutex_t
;
66 typedef char _cups_rwlock_t
;
67 typedef void *_cups_threadkey_t
;
68 # define _CUPS_MUTEX_INITIALIZER 0
69 # define _CUPS_RWLOCK_INITIALIZER 0
70 # define _CUPS_THREADKEY_INITIALIZER (void *)0
71 # define _cupsThreadGetData(k) k
72 # define _cupsThreadSetData(k,p) k=p
73 # endif /* HAVE_PTHREAD_H */
80 extern void _cupsMutexInit(_cups_mutex_t
*mutex
);
81 extern void _cupsMutexLock(_cups_mutex_t
*mutex
);
82 extern void _cupsMutexUnlock(_cups_mutex_t
*mutex
);
83 extern void _cupsRWInit(_cups_rwlock_t
*rwlock
);
84 extern void _cupsRWLockRead(_cups_rwlock_t
*rwlock
);
85 extern void _cupsRWLockWrite(_cups_rwlock_t
*rwlock
);
86 extern void _cupsRWUnlock(_cups_rwlock_t
*rwlock
);
87 extern int _cupsThreadCreate(_cups_thread_func_t func
, void *arg
);
92 # endif /* __cplusplus */
93 #endif /* !_CUPS_THREAD_PRIVATE_H_ */