DocumentationOverviewBuilding ASL Documentation Library Wiki Docs Indices Browse Perforce More InfoRelease NotesWiki Site Search License Success Stories Contributors MediaDownloadPerforce Depots SupportASL SourceForge HomeMailing Lists Discussion Forums Report Bugs Suggest Features Contribute to ASL RSSShort-text newsFull-text news File releases Other Adobe ProjectsAdobe AirAdobe GIL Adobe Labs Adobe Media Gallery Adobe XMP Tamarin project (Mozilla Foundation) Other ResourcesBoostRIAForge SGI STL |
dng_pthread.h00001 /*****************************************************************************/ 00002 // Copyright 2002-2008 Adobe Systems Incorporated 00003 // All Rights Reserved. 00004 // 00005 // NOTICE: Adobe permits you to use, modify, and distribute this file in 00006 // accordance with the terms of the Adobe license agreement accompanying it. 00007 /*****************************************************************************/ 00008 00009 /* $Id: //mondo/workarea/stern/camera_raw/dng_sdk/source/dng_pthread.h#7 $ */ 00010 /* $DateTime: 2009/02/09 22:25:10 $ */ 00011 /* $Change: 539359 $ */ 00012 /* $Author: stern $ */ 00013 00014 /*****************************************************************************/ 00015 00016 #ifndef __dng_pthread__ 00017 #define __dng_pthread__ 00018 00019 /*****************************************************************************/ 00020 00021 #include "dng_flags.h" 00022 00023 /*****************************************************************************/ 00024 00025 #if qDNGThreadSafe 00026 00027 /*****************************************************************************/ 00028 00029 #if !qWinOS 00030 00031 /*****************************************************************************/ 00032 00033 /* Try generic POSIX compile */ 00034 00035 #include <errno.h> 00036 #include <pthread.h> 00037 00038 #define dng_pthread_disassociate() 00039 #define dng_pthread_terminate() 00040 00041 /*****************************************************************************/ 00042 00043 #else 00044 00045 /*****************************************************************************/ 00046 00047 #include <stdlib.h> 00048 00049 #ifdef __cplusplus 00050 extern "C" 00051 { 00052 #endif 00053 00054 /*****************************************************************************/ 00055 00056 #define DNG_ETIMEDOUT 60 /* Operation timed out */ 00057 00058 struct dng_timespec { 00059 long tv_sec; 00060 long tv_nsec; 00061 }; 00062 00063 00064 typedef unsigned long dng_pthread_t; 00065 00066 typedef struct dng_pthread_mutex_impl *dng_pthread_mutex_t; 00067 typedef struct dng_pthread_cond_impl *dng_pthread_cond_t; 00068 typedef unsigned long dng_pthread_key_t; 00069 00070 00071 #define DNG_PTHREAD_MUTEX_INITIALIZER ((struct dng_pthread_mutex_impl *)-1) 00072 #define DNG_PTHREAD_COND_INITIALIZER ((struct dng_pthread_cond_impl *)-1) 00073 00074 struct _dng_pthread_once_t { 00075 int inited; 00076 long semaphore; 00077 }; 00078 00079 typedef struct _dng_pthread_once_t dng_pthread_once_t; 00080 #define DNG_PTHREAD_ONCE_INIT { 0, -1 } 00081 00082 #define dng_pthread_equal(t1, t2) ((t1) == (t2)) 00083 00084 typedef struct dng_pthread_attr_impl *dng_pthread_attr_t; 00085 00086 int dng_pthread_attr_init(dng_pthread_attr_t *attr); 00087 int dng_pthread_attr_destroy(dng_pthread_attr_t *attr); 00088 00089 int dng_pthread_attr_setstacksize(dng_pthread_attr_t *attr, size_t stacksize); 00090 int dng_pthread_attr_getstacksize(const dng_pthread_attr_t *attr, size_t *stacksize); 00091 00092 int dng_pthread_create(dng_pthread_t *thread, const dng_pthread_attr_t * /* attrs */, void * (*func)(void *), void *arg); 00093 int dng_pthread_detach(dng_pthread_t thread); 00094 int dng_pthread_join(dng_pthread_t thread, void **result); 00095 dng_pthread_t dng_pthread_self(); 00096 void dng_pthread_exit(void *result); 00097 00098 #define DNG_PTHREAD_MUTEX_RECURSIVE 0 00099 typedef unsigned long dng_pthread_mutexattr_t; 00100 00101 int dng_pthread_mutexattr_init(dng_pthread_mutexattr_t *mutexattr); 00102 int dng_pthread_mutexattr_settype(dng_pthread_mutexattr_t *mutexattr, int /*the options*/); 00103 00104 int dng_pthread_mutex_init(dng_pthread_mutex_t *mutex, void * /* attrs */); 00105 int dng_pthread_mutex_destroy(dng_pthread_mutex_t *mutex); 00106 int dng_pthread_mutex_lock(dng_pthread_mutex_t *mutex); 00107 int dng_pthread_mutex_unlock(dng_pthread_mutex_t *mutex); 00108 00109 int dng_pthread_cond_init(dng_pthread_cond_t *cond, void * /* attrs */); 00110 int dng_pthread_cond_destroy(dng_pthread_cond_t *cond); 00111 int dng_pthread_cond_wait(dng_pthread_cond_t *cond, dng_pthread_mutex_t *mutex); 00112 int dng_pthread_cond_timedwait(dng_pthread_cond_t *cond, dng_pthread_mutex_t *mutex, struct dng_timespec *latest_time); 00113 int dng_pthread_cond_signal(dng_pthread_cond_t *cond); 00114 int dng_pthread_cond_broadcast(dng_pthread_cond_t *cond); 00115 00116 int dng_pthread_once(dng_pthread_once_t *once, void (*init_func)()); 00117 00118 int dng_pthread_key_create(dng_pthread_key_t * key, void (*destructor) (void *)); 00119 int dng_pthread_key_delete(dng_pthread_key_t key); 00120 int dng_pthread_setspecific(dng_pthread_key_t key, const void *value); 00121 void *dng_pthread_getspecific(dng_pthread_key_t key); 00122 00123 typedef struct dng_pthread_rwlock_impl *dng_pthread_rwlock_t; 00124 typedef void *pthread_rwlockattr_t; 00125 00126 int dng_pthread_rwlock_destroy(dng_pthread_rwlock_t * rwlock); 00127 int dng_pthread_rwlock_init(dng_pthread_rwlock_t * rwlock, const pthread_rwlockattr_t * attrs); 00128 int dng_pthread_rwlock_rdlock(dng_pthread_rwlock_t * rwlock); 00129 int dng_pthread_rwlock_tryrdlock(dng_pthread_rwlock_t * rwlock); 00130 int dng_pthread_rwlock_trywrlock(dng_pthread_rwlock_t * rwlock); 00131 int dng_pthread_rwlock_unlock(dng_pthread_rwlock_t * rwlock); 00132 int dng_pthread_rwlock_wrlock(dng_pthread_rwlock_t * rwlock); 00133 00134 typedef struct dng_pthread_rwlock_impl *dng_pthread_rwlock_t; 00135 typedef void *pthread_rwlockattr_t; 00136 00137 int dng_pthread_rwlock_destroy(dng_pthread_rwlock_t * rwlock); 00138 int dng_pthread_rwlock_init(dng_pthread_rwlock_t * rwlock, const pthread_rwlockattr_t * attrs); 00139 int dng_pthread_rwlock_rdlock(dng_pthread_rwlock_t * rwlock); 00140 int dng_pthread_rwlock_tryrdlock(dng_pthread_rwlock_t * rwlock); 00141 int dng_pthread_rwlock_trywrlock(dng_pthread_rwlock_t * rwlock); 00142 int dng_pthread_rwlock_unlock(dng_pthread_rwlock_t * rwlock); 00143 int dng_pthread_rwlock_wrlock(dng_pthread_rwlock_t * rwlock); 00144 00145 // dng_pthread may maintain per-thread global state. This routine frees that global state. 00146 // there is no need to call this for threads created by dng_pthread and one can call 00147 // dng_pthread routines of a thread after dng_pthread_disassociate as the global state will 00148 // be recreated as necessary. However dng_pthread_disassociate will need to be called again 00149 // and there is a slight performance cost. Do not call this routine while holding a mutex, etc. 00150 void dng_pthread_disassociate(); 00151 00152 void dng_pthread_terminate(); 00153 00154 /*****************************************************************************/ 00155 00156 // Map symbols back to plain pthread names. This whole mechanism is so the DNG pthreads library 00157 // symbols do not collide with another pthread emulation library 00158 // that may be in use in the same linked entity. However if that is the case, it would be far better 00159 // to have the DNG code use the same pthread library as the rest of the code. 00160 00161 #define pthread_t dng_pthread_t 00162 #define pthread_mutex_t dng_pthread_mutex_t 00163 #define pthread_cond_t dng_pthread_cond_t 00164 #define pthread_once_t dng_pthread_once_t 00165 #define pthread_key_t dng_pthread_key_t 00166 00167 #undef PTHREAD_MUTEX_INITIALIZER 00168 #define PTHREAD_MUTEX_INITIALIZER DNG_PTHREAD_MUTEX_INITIALIZER 00169 #undef PTHREAD_COND_INITIALIZER 00170 #define PTHREAD_COND_INITIALIZER DNG_PTHREAD_COND_INITIALIZER 00171 00172 #undef PTHREAD_ONCE_INIT 00173 #define PTHREAD_ONCE_INIT DNG_PTHREAD_ONCE_INIT 00174 00175 #define timespec dng_timespec 00176 00177 /* If it is defined on Windows, it probably has the wrong value... */ 00178 #if defined(WIN32) || !defined(ETIMEDOUT) 00179 #define ETIMEDOUT DNG_ETIMEDOUT 00180 #endif 00181 00182 #define pthread_equal dng_pthread_equal 00183 00184 #define pthread_attr_t dng_pthread_attr_t 00185 00186 #define pthread_attr_init dng_pthread_attr_init 00187 #define pthread_attr_destroy dng_pthread_attr_destroy 00188 00189 #define pthread_attr_setstacksize dng_pthread_attr_setstacksize 00190 #define pthread_attr_getstacksize dng_pthread_attr_getstacksize 00191 00192 #define pthread_create dng_pthread_create 00193 #define pthread_detach dng_pthread_detach 00194 #define pthread_join dng_pthread_join 00195 #define pthread_self dng_pthread_self 00196 #define pthread_exit dng_pthread_exit 00197 00198 #define pthread_mutex_init dng_pthread_mutex_init 00199 #define pthread_mutex_destroy dng_pthread_mutex_destroy 00200 #define pthread_mutex_lock dng_pthread_mutex_lock 00201 #define pthread_mutex_unlock dng_pthread_mutex_unlock 00202 00203 #define pthread_cond_init dng_pthread_cond_init 00204 #define pthread_cond_destroy dng_pthread_cond_destroy 00205 #define pthread_cond_wait dng_pthread_cond_wait 00206 #define pthread_cond_timedwait dng_pthread_cond_timedwait 00207 #define pthread_cond_signal dng_pthread_cond_signal 00208 #define pthread_cond_broadcast dng_pthread_cond_broadcast 00209 00210 #define pthread_once dng_pthread_once 00211 00212 #define pthread_key_create dng_pthread_key_create 00213 #define pthread_key_delete dng_pthread_key_delete 00214 #define pthread_setspecific dng_pthread_setspecific 00215 #define pthread_getspecific dng_pthread_getspecific 00216 00217 #define pthread_rwlock_t dng_pthread_rwlock_t 00218 00219 #define pthread_rwlock_destroy dng_pthread_rwlock_destroy 00220 #define pthread_rwlock_init dng_pthread_rwlock_init 00221 #define pthread_rwlock_rdlock dng_pthread_rwlock_rdlock 00222 #define pthread_rwlock_tryrdlock dng_pthread_rwlock_tryrdlock 00223 #define pthread_rwlock_trywrlock dng_pthread_rwlock_trywrlock 00224 #define pthread_rwlock_unlock dng_pthread_rwlock_unlock 00225 #define pthread_rwlock_wrlock dng_pthread_rwlock_wrlock 00226 00227 /*****************************************************************************/ 00228 00229 #ifdef __cplusplus 00230 } 00231 #endif 00232 00233 /*****************************************************************************/ 00234 00235 #endif 00236 00237 /*****************************************************************************/ 00238 00239 #ifdef __cplusplus 00240 extern "C" 00241 { 00242 #endif 00243 00244 int dng_pthread_now (struct timespec *now); 00245 00246 #ifdef __cplusplus 00247 } 00248 #endif 00249 00250 /*****************************************************************************/ 00251 00252 #endif // qDNGThreadSafe 00253 00254 /*****************************************************************************/ 00255 00256 #endif 00257 00258 /*****************************************************************************/ |