]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/thread-private.h
Several libcups files did not have the Apple license exception notice (STR #4361)
[thirdparty/cups.git] / cups / thread-private.h
CommitLineData
c7017ecc
MS
1/*
2 * "$Id$"
3 *
7e86f2f6 4 * Private threading definitions for CUPS.
c7017ecc 5 *
7e86f2f6 6 * Copyright 2009-2014 by Apple Inc.
c7017ecc 7 *
7e86f2f6
MS
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/".
6539a0af
MS
13 *
14 * This file is subject to the Apple OS-Developed Software exception.
c7017ecc
MS
15 */
16
17#ifndef _CUPS_THREAD_PRIVATE_H_
18# define _CUPS_THREAD_PRIVATE_H_
19
20/*
21 * Include necessary headers...
22 */
23
24# include "config.h"
25
26
27/*
28 * C++ magic...
29 */
30
31# ifdef __cplusplus
32extern "C" {
33# endif /* __cplusplus */
34
35
36# ifdef HAVE_PTHREAD_H
37# include <pthread.h>
38typedef void *(*_cups_thread_func_t)(void *arg);
39typedef pthread_mutex_t _cups_mutex_t;
1106b00e 40typedef pthread_rwlock_t _cups_rwlock_t;
c7017ecc
MS
41typedef pthread_key_t _cups_threadkey_t;
42# define _CUPS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
1106b00e 43# define _CUPS_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
7e86f2f6 44# define _CUPS_THREADKEY_INITIALIZER 0
c7017ecc
MS
45# define _cupsThreadGetData(k) pthread_getspecific(k)
46# define _cupsThreadSetData(k,p) pthread_setspecific(k,p)
47
48# elif defined(WIN32)
49# include <winsock2.h>
50# include <windows.h>
51typedef void *(__stdcall *_cups_thread_func_t)(void *arg);
52typedef struct _cups_mutex_s
53{
f3c17241 54 int m_init; /* Flag for on-demand initialization */
c7017ecc
MS
55 CRITICAL_SECTION m_criticalSection;
56 /* Win32 Critical Section */
57} _cups_mutex_t;
1106b00e 58typedef _cups_mutex_t _cups_rwlock_t; /* TODO: Implement Win32 reader/writer lock */
c7017ecc
MS
59typedef DWORD _cups_threadkey_t;
60# define _CUPS_MUTEX_INITIALIZER { 0, 0 }
1106b00e 61# define _CUPS_RWLOCK_INITIALIZER { 0, 0 }
c7017ecc
MS
62# define _CUPS_THREADKEY_INITIALIZER 0
63# define _cupsThreadGetData(k) TlsGetValue(k)
64# define _cupsThreadSetData(k,p) TlsSetValue(k,p)
65
66# else
f3c17241 67typedef void *(*_cups_thread_func_t)(void *arg);
c7017ecc 68typedef char _cups_mutex_t;
1106b00e 69typedef char _cups_rwlock_t;
c7017ecc
MS
70typedef void *_cups_threadkey_t;
71# define _CUPS_MUTEX_INITIALIZER 0
1106b00e 72# define _CUPS_RWLOCK_INITIALIZER 0
c7017ecc
MS
73# define _CUPS_THREADKEY_INITIALIZER (void *)0
74# define _cupsThreadGetData(k) k
75# define _cupsThreadSetData(k,p) k=p
76# endif /* HAVE_PTHREAD_H */
77
78
79/*
80 * Functions...
81 */
82
1106b00e 83extern void _cupsMutexInit(_cups_mutex_t *mutex);
c7017ecc
MS
84extern void _cupsMutexLock(_cups_mutex_t *mutex);
85extern void _cupsMutexUnlock(_cups_mutex_t *mutex);
1106b00e
MS
86extern void _cupsRWInit(_cups_rwlock_t *rwlock);
87extern void _cupsRWLockRead(_cups_rwlock_t *rwlock);
88extern void _cupsRWLockWrite(_cups_rwlock_t *rwlock);
89extern void _cupsRWUnlock(_cups_rwlock_t *rwlock);
c7017ecc
MS
90extern int _cupsThreadCreate(_cups_thread_func_t func, void *arg);
91
92
93# ifdef __cplusplus
94}
95# endif /* __cplusplus */
96#endif /* !_CUPS_THREAD_PRIVATE_H_ */
97
98/*
99 * End of "$Id$".
100 */