1 /*****************************************************************************/ 2 // Copyright 2006-2008 Adobe Systems Incorporated 3 // All Rights Reserved. 4 // 5 // NOTICE: Adobe permits you to use, modify, and distribute this file in 6 // accordance with the terms of the Adobe license agreement accompanying it. 7 /*****************************************************************************/ 8 9 /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_mutex.h#2 $ */ 10 /* $DateTime: 2012/09/05 12:31:51 $ */ 11 /* $Change: 847652 $ */ 12 /* $Author: tknoll $ */ 13 14 /******************************************************************************/ 15 16 #ifndef __dng_mutex__ 17 #define __dng_mutex__ 18 19 /******************************************************************************/ 20 21 #include "dng_flags.h" 22 23 /******************************************************************************/ 24 25 #include "dng_types.h" 26 27 #if qDNGThreadSafe 28 29 #include "dng_pthread.h" 30 31 #endif 32 33 /******************************************************************************/ 34 35 class dng_mutex 36 { 37 38 public: 39 40 enum 41 { 42 kDNGMutexLevelLeaf = 0x70000000u 43 }; 44 45 dng_mutex (const char *mutexName, 46 uint32 mutexLevel = kDNGMutexLevelLeaf); 47 48 virtual ~dng_mutex (); 49 50 void Lock (); 51 52 void Unlock (); 53 54 const char *MutexName () const; 55 56 protected: 57 58 #if qDNGThreadSafe 59 60 pthread_mutex_t fPthreadMutex; 61 62 const uint32 fMutexLevel; 63 64 uint32 fRecursiveLockCount; 65 66 dng_mutex *fPrevHeldMutex; 67 68 const char * const fMutexName; 69 70 friend class dng_condition; 71 72 #endif 73 74 private: 75 76 // Hidden copy constructor and assignment operator. 77 78 dng_mutex (const dng_mutex &mutex); 79 80 dng_mutex & operator= (const dng_mutex &mutex); 81 82 }; 83 84 /*****************************************************************************/ 85 86 class dng_lock_mutex 87 { 88 89 private: 90 91 dng_mutex *fMutex; 92 93 public: 94 95 dng_lock_mutex (dng_mutex *mutex); 96 97 ~dng_lock_mutex (); 98 99 private: 100 101 // Hidden copy constructor and assignment operator. 102 103 dng_lock_mutex (const dng_lock_mutex &lock); 104 105 dng_lock_mutex & operator= (const dng_lock_mutex &lock); 106 107 }; 108 109 /*****************************************************************************/ 110 111 class dng_unlock_mutex 112 { 113 114 private: 115 116 dng_mutex *fMutex; 117 118 public: 119 120 dng_unlock_mutex (dng_mutex *mutex); 121 122 ~dng_unlock_mutex (); 123 124 private: 125 126 // Hidden copy constructor and assignment operator. 127 128 dng_unlock_mutex (const dng_unlock_mutex &unlock); 129 130 dng_unlock_mutex & operator= (const dng_unlock_mutex &unlock); 131 132 }; 133 134 /*****************************************************************************/ 135 136 #if qDNGThreadSafe 137 138 /*****************************************************************************/ 139 140 class dng_condition 141 { 142 143 public: 144 145 dng_condition (); 146 147 ~dng_condition (); 148 149 bool Wait (dng_mutex &mutex, double timeoutSecs = -1.0); 150 151 void Signal (); 152 153 void Broadcast (); 154 155 protected: 156 157 pthread_cond_t fPthreadCondition; 158 159 private: 160 161 // Hidden copy constructor and assignment operator. 162 163 dng_condition (const dng_condition &condition); 164 165 dng_condition & operator= (const dng_condition &condition); 166 167 }; 168 169 /*****************************************************************************/ 170 171 #endif // qDNGThreadSafe 172 173 /*****************************************************************************/ 174 175 #endif 176 177 /*****************************************************************************/ 178