зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1312087 - part 0 - use PTHREAD_MUTEX_ADAPTIVE_NP mutexes on Linux/glibc; r=erahm
This matches NSPR's behavior for its PRLock type.
This commit is contained in:
Родитель
838290fd27
Коммит
5b67a265dc
|
@ -27,22 +27,35 @@ mozilla::detail::MutexImpl::MutexImpl()
|
|||
{
|
||||
pthread_mutexattr_t* attrp = nullptr;
|
||||
|
||||
#ifdef DEBUG
|
||||
// glibc's adaptive mutexes spin for a short number of tries before sleeping.
|
||||
// NSPR's locks did this, too, and it seems like a reasonable thing to do.
|
||||
#if defined(__linux__) && defined(__GLIBC__)
|
||||
#define ADAPTIVE_MUTEX_SUPPORTED
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG)
|
||||
#define ATTR_REQUIRED
|
||||
#define MUTEX_KIND PTHREAD_MUTEX_ERRORCHECK
|
||||
#elif defined(ADAPTIVE_MUTEX_SUPPORTED)
|
||||
#define ATTR_REQUIRED
|
||||
#define MUTEX_KIND PTHREAD_MUTEX_ADAPTIVE_NP
|
||||
#endif
|
||||
|
||||
#if defined(ATTR_REQUIRED)
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
TRY_CALL_PTHREADS(pthread_mutexattr_init(&attr),
|
||||
"mozilla::detail::MutexImpl::MutexImpl: pthread_mutexattr_init failed");
|
||||
|
||||
TRY_CALL_PTHREADS(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK),
|
||||
TRY_CALL_PTHREADS(pthread_mutexattr_settype(&attr, MUTEX_KIND),
|
||||
"mozilla::detail::MutexImpl::MutexImpl: pthread_mutexattr_settype failed");
|
||||
|
||||
attrp = &attr;
|
||||
#endif
|
||||
|
||||
TRY_CALL_PTHREADS(pthread_mutex_init(&platformData()->ptMutex, attrp),
|
||||
"mozilla::detail::MutexImpl::MutexImpl: pthread_mutex_init failed");
|
||||
|
||||
#ifdef DEBUG
|
||||
#if defined(ATTR_REQUIRED)
|
||||
TRY_CALL_PTHREADS(pthread_mutexattr_destroy(&attr),
|
||||
"mozilla::detail::MutexImpl::MutexImpl: pthread_mutexattr_destroy failed");
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче