Bug 1062533 - part 4 - expose a tryLock method for PlatformMutex; r=mccr8

Chromium IPC locks have this and the API gets used, so we need to expose
it ourselves if we're going to use our locks in place of the Chromium
IPC locks.  This patch changes the mozglue parts; tweaking the xpcom
parts is the next patch.
This commit is contained in:
Nathan Froyd 2019-01-09 11:09:24 -04:00
Родитель 99da46a21c
Коммит 42bd2abf83
3 изменённых файлов: 12 добавлений и 5 удалений

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

@ -127,8 +127,9 @@ inline void mozilla::detail::MutexImpl::mutexLock() {
"mozilla::detail::MutexImpl::mutexLock: pthread_mutex_lock failed");
}
#ifdef XP_DARWIN
inline bool mozilla::detail::MutexImpl::mutexTryLock() {
bool mozilla::detail::MutexImpl::tryLock() { return mutexTryLock(); }
bool mozilla::detail::MutexImpl::mutexTryLock() {
int result = pthread_mutex_trylock(&platformData()->ptMutex);
if (result == 0) {
return true;
@ -142,7 +143,6 @@ inline bool mozilla::detail::MutexImpl::mutexTryLock() {
result,
"mozilla::detail::MutexImpl::mutexTryLock: pthread_mutex_trylock failed");
}
#endif
void mozilla::detail::MutexImpl::lock() {
#ifndef XP_DARWIN

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

@ -22,6 +22,12 @@ void mozilla::detail::MutexImpl::lock() {
AcquireSRWLockExclusive(&platformData()->lock);
}
bool mozilla::detail::MutexImpl::tryLock() { return mutexTryLock(); }
bool mozilla::detail::MutexImpl::mutexTryLock() {
return !!TryAcquireSRWLockExclusive(&platformData()->lock);
}
void mozilla::detail::MutexImpl::unlock() {
ReleaseSRWLockExclusive(&platformData()->lock);
}

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

@ -33,6 +33,9 @@ class MutexImpl {
protected:
MFBT_API void lock();
MFBT_API void unlock();
// We have a separate, forwarding API so internal uses don't have to go
// through the PLT.
MFBT_API bool tryLock();
private:
MutexImpl(const MutexImpl&) = delete;
@ -42,9 +45,7 @@ class MutexImpl {
bool operator==(const MutexImpl& rhs) = delete;
void mutexLock();
#ifdef XP_DARWIN
bool mutexTryLock();
#endif
PlatformData* platformData();