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:
Nathan Froyd 2017-03-21 11:20:36 -04:00
Родитель 838290fd27
Коммит 5b67a265dc
1 изменённых файлов: 17 добавлений и 4 удалений

Просмотреть файл

@ -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