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