/* -*- 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/. */
staticvoid InitMutex(pthread_mutex_t* mMutex) {
pthread_mutexattr_t mutexAttributes;
pthread_mutexattr_init(&mutexAttributes); // Make the mutex reentrant so it behaves the same as a win32 mutex if (pthread_mutexattr_settype(&mutexAttributes, PTHREAD_MUTEX_RECURSIVE)) {
MOZ_CRASH();
} if (pthread_mutexattr_setpshared(&mutexAttributes, PTHREAD_PROCESS_SHARED)) {
MOZ_CRASH();
}
if (pthread_mutex_init(mMutex, &mutexAttributes)) {
MOZ_CRASH();
}
}
CrossProcessMutex::CrossProcessMutex(constchar*)
: mMutex(nullptr), mCount(nullptr) { #ifdefined(MOZ_SANDBOX) // POSIX mutexes in shared memory aren't guaranteed to be safe - and // they specifically are not on Linux.
MOZ_RELEASE_ASSERT(false); #endif
mSharedBuffer = new ipc::SharedMemory; if (!mSharedBuffer->Create(sizeof(MutexData))) {
MOZ_CRASH();
}
if (!mSharedBuffer->Map(sizeof(MutexData))) {
MOZ_CRASH();
}
MutexData* data = static_cast<MutexData*>(mSharedBuffer->Memory());
if (count == 0) { // The other side has already let go of their CrossProcessMutex, so now // mMutex is garbage. We need to re-initialize it.
InitMutex(mMutex);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.