Overview
Comment: | Use recursive pthread mutexes if available. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
1e10b330665552727d33e0a94d806ceb |
User & Date: | js on 2012-08-05 17:22:43 |
Other Links: | manifest | tags |
Context
2012-08-05
| ||
17:34 | Add OFRecursiveMutex class. check-in: 6069030651 user: js tags: trunk | |
17:22 | Use recursive pthread mutexes if available. check-in: 1e10b33066 user: js tags: trunk | |
16:52 | Fix a possible race condition in initialize_class. check-in: 8f02ff02dc user: js tags: trunk | |
Changes
Modified configure.ac from [a704aa9fe3] to [0c2ce536c1].
︙ | |||
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | + + + + + + + + + + + + + | ;; *) ACX_PTHREAD([ CPPLAGS="$CPPFLAGS $PTHREAD_CFLAGS" LIBS="$LIBS $PTHREAD_LIBS" AC_DEFINE(OF_HAVE_PTHREADS, 1, [Whether we have pthreads]) AC_TRY_COMPILE([ #include <pthread.h> ], [ pthread_mutexattr_t attr; pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); ], [ AC_DEFINE(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES, 1, [If pthread mutexes can be recursive]) ]) AC_CHECK_FUNC(pthread_spin_lock, [ AC_DEFINE(OF_HAVE_PTHREAD_SPINLOCKS, 1, [Whether we have pthread spinlocks]) ]) AC_CHECK_FUNC(sched_yield, [ AC_DEFINE(OF_HAVE_SCHED_YIELD, 1, [Whether we have sched_yield]) ]) ], [ AC_MSG_ERROR(No supported threads found!) ]) |
︙ |
Modified src/objfw-defs.h.in from [35b1efd8d0] to [13f2356be6].
︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | + | #undef OF_HAVE_GCC_ATOMIC_OPS #undef OF_HAVE_OPTIONAL_PROTOCOLS #undef OF_HAVE_OSATOMIC #undef OF_HAVE_OSATOMIC_64 #undef OF_HAVE_PROPERTIES #undef OF_HAVE_PTHREADS #undef OF_HAVE_PTHREAD_SPINLOCKS #undef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES #undef OF_HAVE_SCHED_YIELD #undef OF_HAVE_SYS_SELECT_H #undef OF_OBJFW_RUNTIME #undef OF_PLUGINS #undef OF_THREADS #undef SIZE_MAX |
Modified src/threading.h from [f15e1e67ea] to [aa1078d8fa].
︙ | |||
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | + + + + | # define OF_SPINCOUNT 10 #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) typedef pthread_spinlock_t of_spinlock_t; #else typedef of_mutex_t of_spinlock_t; #endif #ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES # define of_rmutex_t of_mutex_t #else typedef struct { of_mutex_t mutex; of_tlskey_t count; } of_rmutex_t; #endif #if defined(OF_HAVE_PTHREADS) # define of_thread_is_current(t) pthread_equal(t, pthread_self()) # define of_thread_current pthread_self #elif defined(_WIN32) # define of_thread_is_current(t) (t == GetCurrentThread()) # define of_thread_current GetCurrentThread |
︙ | |||
365 366 367 368 369 370 371 372 373 374 375 376 377 378 | 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | + + + + + + + + + + + + + + + + + + + + + + + + + | #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return !pthread_spin_destroy(spinlock); #else return of_mutex_free(spinlock); #endif } #ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES static OF_INLINE BOOL of_rmutex_new(of_mutex_t *mutex) { pthread_mutexattr_t attr; if (pthread_mutexattr_init(&attr)) return NO; if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) return NO; if (pthread_mutex_init(mutex, &attr)) return NO; if (pthread_mutexattr_destroy(&attr)) return NO; return YES; } # define of_rmutex_lock of_mutex_lock # define of_rmutex_unlock of_mutex_unlock # define of_rmutex_free of_mutex_free #else static OF_INLINE BOOL of_rmutex_new(of_rmutex_t *rmutex) { if (!of_mutex_new(&rmutex->mutex)) return NO; if (!of_tlskey_new(&rmutex->count)) |
︙ | |||
430 431 432 433 434 435 436 | 459 460 461 462 463 464 465 466 | + | return NO; if (!of_tlskey_free(rmutex->count)) return NO; return YES; } #endif |