Mercurial > dwindows
comparison gtk/dw.c @ 239:403b07f873e1
Use a pointer for HMTX instead of a pthread_mutex_t struct.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 18 Feb 2003 20:09:04 +0000 |
parents | efa724294b5f |
children | 00d2b1bcf036 |
comparison
equal
deleted
inserted
replaced
238:13d3de3f1e83 | 239:403b07f873e1 |
---|---|
5255 /* | 5255 /* |
5256 * Returns the handle to an unnamed mutex semaphore. | 5256 * Returns the handle to an unnamed mutex semaphore. |
5257 */ | 5257 */ |
5258 HMTX dw_mutex_new(void) | 5258 HMTX dw_mutex_new(void) |
5259 { | 5259 { |
5260 HMTX mutex; | 5260 HMTX mutex = malloc(sizeof(pthread_mutex_t)); |
5261 | 5261 |
5262 pthread_mutex_init(&mutex, NULL); | 5262 pthread_mutex_init(mutex, NULL); |
5263 return mutex; | 5263 return mutex; |
5264 } | 5264 } |
5265 | 5265 |
5266 /* | 5266 /* |
5267 * Closes a semaphore created by dw_mutex_new(). | 5267 * Closes a semaphore created by dw_mutex_new(). |
5268 * Parameters: | 5268 * Parameters: |
5269 * mutex: The handle to the mutex returned by dw_mutex_new(). | 5269 * mutex: The handle to the mutex returned by dw_mutex_new(). |
5270 */ | 5270 */ |
5271 void dw_mutex_close(HMTX mutex) | 5271 void dw_mutex_close(HMTX mutex) |
5272 { | 5272 { |
5273 pthread_mutex_destroy(&mutex); | 5273 if(mutex) |
5274 { | |
5275 pthread_mutex_destroy(mutex); | |
5276 free(mutex); | |
5277 } | |
5274 } | 5278 } |
5275 | 5279 |
5276 /* | 5280 /* |
5277 * Tries to gain access to the semaphore, if it can't it blocks. | 5281 * Tries to gain access to the semaphore, if it can't it blocks. |
5278 * Parameters: | 5282 * Parameters: |
5284 * the GTK mutex so we don't deadlock. | 5288 * the GTK mutex so we don't deadlock. |
5285 */ | 5289 */ |
5286 if(pthread_self() == _dw_thread) | 5290 if(pthread_self() == _dw_thread) |
5287 gdk_threads_leave(); | 5291 gdk_threads_leave(); |
5288 | 5292 |
5289 pthread_mutex_lock(&mutex); | 5293 pthread_mutex_lock(mutex); |
5290 | 5294 |
5291 /* And of course relock it when we have acquired the mutext */ | 5295 /* And of course relock it when we have acquired the mutext */ |
5292 if(pthread_self() == _dw_thread) | 5296 if(pthread_self() == _dw_thread) |
5293 gdk_threads_enter(); | 5297 gdk_threads_enter(); |
5294 } | 5298 } |
5298 * Parameters: | 5302 * Parameters: |
5299 * mutex: The handle to the mutex returned by dw_mutex_new(). | 5303 * mutex: The handle to the mutex returned by dw_mutex_new(). |
5300 */ | 5304 */ |
5301 void dw_mutex_unlock(HMTX mutex) | 5305 void dw_mutex_unlock(HMTX mutex) |
5302 { | 5306 { |
5303 pthread_mutex_unlock(&mutex); | 5307 pthread_mutex_unlock(mutex); |
5304 } | 5308 } |
5305 | 5309 |
5306 /* | 5310 /* |
5307 * Returns the handle to an unnamed event semaphore. | 5311 * Returns the handle to an unnamed event semaphore. |
5308 */ | 5312 */ |