diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/threading/posix/MutexImpl.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/threading/posix/MutexImpl.cpp')
-rw-r--r-- | js/src/threading/posix/MutexImpl.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/js/src/threading/posix/MutexImpl.cpp b/js/src/threading/posix/MutexImpl.cpp new file mode 100644 index 000000000..1d406400f --- /dev/null +++ b/js/src/threading/posix/MutexImpl.cpp @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include <errno.h> +#include <pthread.h> +#include <stdio.h> + +#include "js/Utility.h" + +#include "threading/Mutex.h" +#include "threading/posix/MutexPlatformData.h" + +#define TRY_CALL_PTHREADS(call, msg) \ + { \ + int result = (call); \ + if (result != 0) { \ + errno = result; \ + perror(msg); \ + MOZ_CRASH(msg); \ + } \ + } + +js::detail::MutexImpl::MutexImpl() +{ + AutoEnterOOMUnsafeRegion oom; + platformData_ = js_new<PlatformData>(); + if (!platformData_) + oom.crash("js::detail::MutexImpl::MutexImpl"); + + pthread_mutexattr_t* attrp = nullptr; + +#ifdef DEBUG + pthread_mutexattr_t attr; + + TRY_CALL_PTHREADS(pthread_mutexattr_init(&attr), + "js::detail::MutexImpl::MutexImpl: pthread_mutexattr_init failed"); + + TRY_CALL_PTHREADS(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK), + "js::detail::MutexImpl::MutexImpl: pthread_mutexattr_settype failed"); + + attrp = &attr; +#endif + + TRY_CALL_PTHREADS(pthread_mutex_init(&platformData()->ptMutex, attrp), + "js::detail::MutexImpl::MutexImpl: pthread_mutex_init failed"); + +#ifdef DEBUG + TRY_CALL_PTHREADS(pthread_mutexattr_destroy(&attr), + "js::detail::MutexImpl::MutexImpl: pthread_mutexattr_destroy failed"); +#endif +} + +js::detail::MutexImpl::~MutexImpl() +{ + if (!platformData_) + return; + + TRY_CALL_PTHREADS(pthread_mutex_destroy(&platformData()->ptMutex), + "js::detail::MutexImpl::~MutexImpl: pthread_mutex_destroy failed"); + + js_delete(platformData()); +} + +void +js::detail::MutexImpl::lock() +{ + TRY_CALL_PTHREADS(pthread_mutex_lock(&platformData()->ptMutex), + "js::detail::MutexImpl::lock: pthread_mutex_lock failed"); +} + +void +js::detail::MutexImpl::unlock() +{ + TRY_CALL_PTHREADS(pthread_mutex_unlock(&platformData()->ptMutex), + "js::detail::MutexImpl::unlock: pthread_mutex_unlock failed"); +} + +#undef TRY_CALL_PTHREADS |