Changeset 4575
- Timestamp:
- 11/05/08 08:57:26 (2 months ago)
- Files:
-
- trunk/src/libstrongswan/utils/mutex.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/libstrongswan/utils/mutex.c
r4449 r4575 47 47 pthread_mutex_t mutex; 48 48 49 #ifdef LOCK_PROFILER 50 /** 51 * how long threads have waited for the lock in this mutex so far 52 */ 53 struct timeval waited; 54 55 /** 56 * creator of the mutex 57 */ 58 void *stack[10]; 59 60 /** 61 * number of pointers in stack 62 */ 63 int stack_size; 64 #endif /* LOCK_PROFILER */ 65 49 66 /** 50 67 * is this a recursiv emutex, implementing private_r_mutex_t? … … 90 107 }; 91 108 109 #ifdef LOCK_PROFILER 110 111 #include <execinfo.h> 112 113 /** 114 * print mutex locking statistics 115 */ 116 static void print_stats(private_mutex_t *this) 117 { 118 int i; 119 120 DBG1("waited %d.%06ds in mutex, created at:", 121 this->waited.tv_sec, this->waited.tv_usec); 122 for (i = 0; i < this->stack_size; i++) 123 { 124 DBG1(" %p", this->stack[i]); 125 } 126 } 127 128 static void init_stats(private_mutex_t *this) 129 { 130 this->stack_size = backtrace(this->stack, countof(this->stack)); 131 timerclear(&this->waited); 132 } 133 92 134 /** 93 135 * Implementation of mutex_t.lock. … … 95 137 static void lock(private_mutex_t *this) 96 138 { 139 struct timeval start, end, diff; 140 141 gettimeofday(&start, NULL); 97 142 if (pthread_mutex_lock(&this->mutex)) 98 143 { 99 144 DBG1("!!!! MUTEX %sLOCK ERROR, your code is buggy !!!", ""); 100 145 } 101 } 146 gettimeofday(&end, NULL); 147 148 timersub(&end, &start, &diff); 149 timeradd(&this->waited, &diff, &this->waited); 150 } 151 #else /* !LOCK_PROFILER */ 152 153 /** dummy implementations */ 154 static void print_stats(private_mutex_t *this) {} 155 static void init_stats(private_mutex_t *this) {} 156 157 /** 158 * Implementation of mutex_t.lock. 159 */ 160 static void lock(private_mutex_t *this) 161 { 162 if (pthread_mutex_lock(&this->mutex)) 163 { 164 DBG1("!!!! MUTEX %sLOCK ERROR, your code is buggy !!!", ""); 165 } 166 } 167 #endif /* LOCK_PROFILER */ 102 168 103 169 /** … … 159 225 static void mutex_destroy(private_mutex_t *this) 160 226 { 227 print_stats(this); 161 228 pthread_mutex_destroy(&this->mutex); 162 229 free(this); … … 168 235 static void mutex_destroy_r(private_r_mutex_t *this) 169 236 { 237 print_stats(&this->generic); 170 238 pthread_mutex_destroy(&this->generic.mutex); 171 239 pthread_key_delete(this->times); … … 191 259 pthread_key_create(&this->times, NULL); 192 260 this->generic.recursive = TRUE; 261 init_stats(&this->generic); 193 262 this->thread = 0; 194 263 … … 206 275 pthread_mutex_init(&this->mutex, NULL); 207 276 this->recursive = FALSE; 277 init_stats(this); 208 278 209 279 return &this->public;
