1*5e7646d2SAndroid Build Coastguard Worker /* 2*5e7646d2SAndroid Build Coastguard Worker * Private threading definitions for CUPS. 3*5e7646d2SAndroid Build Coastguard Worker * 4*5e7646d2SAndroid Build Coastguard Worker * Copyright 2009-2017 by Apple Inc. 5*5e7646d2SAndroid Build Coastguard Worker * 6*5e7646d2SAndroid Build Coastguard Worker * Licensed under Apache License v2.0. See the file "LICENSE" for more information. 7*5e7646d2SAndroid Build Coastguard Worker */ 8*5e7646d2SAndroid Build Coastguard Worker 9*5e7646d2SAndroid Build Coastguard Worker #ifndef _CUPS_THREAD_PRIVATE_H_ 10*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_THREAD_PRIVATE_H_ 11*5e7646d2SAndroid Build Coastguard Worker 12*5e7646d2SAndroid Build Coastguard Worker /* 13*5e7646d2SAndroid Build Coastguard Worker * Include necessary headers... 14*5e7646d2SAndroid Build Coastguard Worker */ 15*5e7646d2SAndroid Build Coastguard Worker 16*5e7646d2SAndroid Build Coastguard Worker # include "config.h" 17*5e7646d2SAndroid Build Coastguard Worker # include <cups/versioning.h> 18*5e7646d2SAndroid Build Coastguard Worker 19*5e7646d2SAndroid Build Coastguard Worker 20*5e7646d2SAndroid Build Coastguard Worker /* 21*5e7646d2SAndroid Build Coastguard Worker * C++ magic... 22*5e7646d2SAndroid Build Coastguard Worker */ 23*5e7646d2SAndroid Build Coastguard Worker 24*5e7646d2SAndroid Build Coastguard Worker # ifdef __cplusplus 25*5e7646d2SAndroid Build Coastguard Worker extern "C" { 26*5e7646d2SAndroid Build Coastguard Worker # endif /* __cplusplus */ 27*5e7646d2SAndroid Build Coastguard Worker 28*5e7646d2SAndroid Build Coastguard Worker 29*5e7646d2SAndroid Build Coastguard Worker # ifdef HAVE_PTHREAD_H /* POSIX threading */ 30*5e7646d2SAndroid Build Coastguard Worker # include <pthread.h> 31*5e7646d2SAndroid Build Coastguard Worker typedef void *(*_cups_thread_func_t)(void *arg); 32*5e7646d2SAndroid Build Coastguard Worker typedef pthread_t _cups_thread_t; 33*5e7646d2SAndroid Build Coastguard Worker typedef pthread_cond_t _cups_cond_t; 34*5e7646d2SAndroid Build Coastguard Worker typedef pthread_mutex_t _cups_mutex_t; 35*5e7646d2SAndroid Build Coastguard Worker typedef pthread_rwlock_t _cups_rwlock_t; 36*5e7646d2SAndroid Build Coastguard Worker typedef pthread_key_t _cups_threadkey_t; 37*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_COND_INITIALIZER PTHREAD_COND_INITIALIZER 38*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER 39*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER 40*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_THREADKEY_INITIALIZER 0 41*5e7646d2SAndroid Build Coastguard Worker # define _cupsThreadGetData(k) pthread_getspecific(k) 42*5e7646d2SAndroid Build Coastguard Worker # define _cupsThreadSetData(k,p) pthread_setspecific(k,p) 43*5e7646d2SAndroid Build Coastguard Worker 44*5e7646d2SAndroid Build Coastguard Worker # elif defined(_WIN32) /* Windows threading */ 45*5e7646d2SAndroid Build Coastguard Worker # include <winsock2.h> 46*5e7646d2SAndroid Build Coastguard Worker # include <windows.h> 47*5e7646d2SAndroid Build Coastguard Worker typedef void *(__stdcall *_cups_thread_func_t)(void *arg); 48*5e7646d2SAndroid Build Coastguard Worker typedef int _cups_thread_t; 49*5e7646d2SAndroid Build Coastguard Worker typedef char _cups_cond_t; /* TODO: Implement Win32 conditional */ 50*5e7646d2SAndroid Build Coastguard Worker typedef struct _cups_mutex_s 51*5e7646d2SAndroid Build Coastguard Worker { 52*5e7646d2SAndroid Build Coastguard Worker int m_init; /* Flag for on-demand initialization */ 53*5e7646d2SAndroid Build Coastguard Worker CRITICAL_SECTION m_criticalSection; 54*5e7646d2SAndroid Build Coastguard Worker /* Win32 Critical Section */ 55*5e7646d2SAndroid Build Coastguard Worker } _cups_mutex_t; 56*5e7646d2SAndroid Build Coastguard Worker typedef _cups_mutex_t _cups_rwlock_t; /* TODO: Implement Win32 reader/writer lock */ 57*5e7646d2SAndroid Build Coastguard Worker typedef DWORD _cups_threadkey_t; 58*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_COND_INITIALIZER 0 59*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_MUTEX_INITIALIZER { 0, 0 } 60*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_RWLOCK_INITIALIZER { 0, 0 } 61*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_THREADKEY_INITIALIZER 0 62*5e7646d2SAndroid Build Coastguard Worker # define _cupsThreadGetData(k) TlsGetValue(k) 63*5e7646d2SAndroid Build Coastguard Worker # define _cupsThreadSetData(k,p) TlsSetValue(k,p) 64*5e7646d2SAndroid Build Coastguard Worker 65*5e7646d2SAndroid Build Coastguard Worker # else /* No threading */ 66*5e7646d2SAndroid Build Coastguard Worker typedef void *(*_cups_thread_func_t)(void *arg); 67*5e7646d2SAndroid Build Coastguard Worker typedef int _cups_thread_t; 68*5e7646d2SAndroid Build Coastguard Worker typedef char _cups_cond_t; 69*5e7646d2SAndroid Build Coastguard Worker typedef char _cups_mutex_t; 70*5e7646d2SAndroid Build Coastguard Worker typedef char _cups_rwlock_t; 71*5e7646d2SAndroid Build Coastguard Worker typedef void *_cups_threadkey_t; 72*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_COND_INITIALIZER 0 73*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_MUTEX_INITIALIZER 0 74*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_RWLOCK_INITIALIZER 0 75*5e7646d2SAndroid Build Coastguard Worker # define _CUPS_THREADKEY_INITIALIZER (void *)0 76*5e7646d2SAndroid Build Coastguard Worker # define _cupsThreadGetData(k) k 77*5e7646d2SAndroid Build Coastguard Worker # define _cupsThreadSetData(k,p) k=p 78*5e7646d2SAndroid Build Coastguard Worker # endif /* HAVE_PTHREAD_H */ 79*5e7646d2SAndroid Build Coastguard Worker 80*5e7646d2SAndroid Build Coastguard Worker 81*5e7646d2SAndroid Build Coastguard Worker /* 82*5e7646d2SAndroid Build Coastguard Worker * Functions... 83*5e7646d2SAndroid Build Coastguard Worker */ 84*5e7646d2SAndroid Build Coastguard Worker 85*5e7646d2SAndroid Build Coastguard Worker extern void _cupsCondBroadcast(_cups_cond_t *cond) _CUPS_PRIVATE; 86*5e7646d2SAndroid Build Coastguard Worker extern void _cupsCondInit(_cups_cond_t *cond) _CUPS_PRIVATE; 87*5e7646d2SAndroid Build Coastguard Worker extern void _cupsCondWait(_cups_cond_t *cond, _cups_mutex_t *mutex, double timeout) _CUPS_PRIVATE; 88*5e7646d2SAndroid Build Coastguard Worker extern void _cupsMutexInit(_cups_mutex_t *mutex) _CUPS_PRIVATE; 89*5e7646d2SAndroid Build Coastguard Worker extern void _cupsMutexLock(_cups_mutex_t *mutex) _CUPS_PRIVATE; 90*5e7646d2SAndroid Build Coastguard Worker extern void _cupsMutexUnlock(_cups_mutex_t *mutex) _CUPS_PRIVATE; 91*5e7646d2SAndroid Build Coastguard Worker extern void _cupsRWInit(_cups_rwlock_t *rwlock) _CUPS_PRIVATE; 92*5e7646d2SAndroid Build Coastguard Worker extern void _cupsRWLockRead(_cups_rwlock_t *rwlock) _CUPS_PRIVATE; 93*5e7646d2SAndroid Build Coastguard Worker extern void _cupsRWLockWrite(_cups_rwlock_t *rwlock) _CUPS_PRIVATE; 94*5e7646d2SAndroid Build Coastguard Worker extern void _cupsRWUnlock(_cups_rwlock_t *rwlock) _CUPS_PRIVATE; 95*5e7646d2SAndroid Build Coastguard Worker extern void _cupsThreadCancel(_cups_thread_t thread) _CUPS_PRIVATE; 96*5e7646d2SAndroid Build Coastguard Worker extern _cups_thread_t _cupsThreadCreate(_cups_thread_func_t func, void *arg) _CUPS_PRIVATE; 97*5e7646d2SAndroid Build Coastguard Worker extern void _cupsThreadDetach(_cups_thread_t thread) _CUPS_PRIVATE; 98*5e7646d2SAndroid Build Coastguard Worker extern void *_cupsThreadWait(_cups_thread_t thread) _CUPS_PRIVATE; 99*5e7646d2SAndroid Build Coastguard Worker 100*5e7646d2SAndroid Build Coastguard Worker # ifdef __cplusplus 101*5e7646d2SAndroid Build Coastguard Worker } 102*5e7646d2SAndroid Build Coastguard Worker # endif /* __cplusplus */ 103*5e7646d2SAndroid Build Coastguard Worker #endif /* !_CUPS_THREAD_PRIVATE_H_ */ 104