]>
Commit | Line | Data |
---|---|---|
c7017ecc MS |
1 | /* |
2 | * "$Id$" | |
3 | * | |
4 | * Private threading definitions for CUPS. | |
5 | * | |
6 | * Copyright 2009-2010 by Apple Inc. | |
7 | * | |
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/". | |
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 | |
35 | # include <pthread.h> | |
36 | typedef void *(*_cups_thread_func_t)(void *arg); | |
37 | typedef pthread_mutex_t _cups_mutex_t; | |
38 | typedef pthread_key_t _cups_threadkey_t; | |
39 | # define _CUPS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER | |
40 | # define _CUPS_THREADKEY_INITIALIZER -1 | |
41 | # define _cupsThreadGetData(k) pthread_getspecific(k) | |
42 | # define _cupsThreadSetData(k,p) pthread_setspecific(k,p) | |
43 | ||
44 | # elif defined(WIN32) | |
45 | # include <winsock2.h> | |
46 | # include <windows.h> | |
47 | typedef void *(__stdcall *_cups_thread_func_t)(void *arg); | |
48 | typedef struct _cups_mutex_s | |
49 | { | |
50 | int m_init; /* Flag for on-demand initialization */ | |
51 | CRITICAL_SECTION m_criticalSection; | |
52 | /* Win32 Critical Section */ | |
53 | } _cups_mutex_t; | |
54 | typedef DWORD _cups_threadkey_t; | |
55 | # define _CUPS_MUTEX_INITIALIZER { 0, 0 } | |
56 | # define _CUPS_THREADKEY_INITIALIZER 0 | |
57 | # define _cupsThreadGetData(k) TlsGetValue(k) | |
58 | # define _cupsThreadSetData(k,p) TlsSetValue(k,p) | |
59 | ||
60 | # else | |
61 | typedef char _cups_mutex_t; | |
62 | typedef void *_cups_threadkey_t; | |
63 | # define _CUPS_MUTEX_INITIALIZER 0 | |
64 | # define _CUPS_THREADKEY_INITIALIZER (void *)0 | |
65 | # define _cupsThreadGetData(k) k | |
66 | # define _cupsThreadSetData(k,p) k=p | |
67 | # endif /* HAVE_PTHREAD_H */ | |
68 | ||
69 | ||
70 | /* | |
71 | * Functions... | |
72 | */ | |
73 | ||
74 | extern void _cupsMutexLock(_cups_mutex_t *mutex); | |
75 | extern void _cupsMutexUnlock(_cups_mutex_t *mutex); | |
76 | extern int _cupsThreadCreate(_cups_thread_func_t func, void *arg); | |
77 | ||
78 | ||
79 | # ifdef __cplusplus | |
80 | } | |
81 | # endif /* __cplusplus */ | |
82 | #endif /* !_CUPS_THREAD_PRIVATE_H_ */ | |
83 | ||
84 | /* | |
85 | * End of "$Id$". | |
86 | */ |