Quellcode-Bibliothek CrossProcessSemaphore_posix.cpp
Sprache: C
/* -*- 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/. */
if (!sharedBuffer->IsHandleValid(aHandle)) { return nullptr;
}
if (!sharedBuffer->SetHandle(std::move(aHandle),
ipc::SharedMemory::RightsReadWrite)) { return nullptr;
}
if (!sharedBuffer->Map(sizeof(SemaphoreData))) { return nullptr;
}
sharedBuffer->CloseHandle();
SemaphoreData* data = static_cast<SemaphoreData*>(sharedBuffer->Memory());
if (!data) { return nullptr;
}
int32_t oldCount = data->mRefCount++; if (oldCount == 0) { // The other side has already let go of their CrossProcessSemaphore, so now // mSemaphore is garbage. We need to re-initialize it. if (sem_init(&data->mSemaphore, 1, data->mInitialValue)) {
data->mRefCount--; return nullptr;
}
}
CrossProcessSemaphore* sem = new CrossProcessSemaphore;
sem->mSharedBuffer = sharedBuffer;
sem->mSemaphore = &data->mSemaphore;
sem->mRefCount = &data->mRefCount; return sem;
}
if (oldCount == 0) { // Nothing can be done if the destroy fails so ignore return code.
Unused << sem_destroy(mSemaphore);
}
MOZ_COUNT_DTOR(CrossProcessSemaphore);
}
bool CrossProcessSemaphore::Wait(const Maybe<TimeDuration>& aWaitTime) {
MOZ_ASSERT(*mRefCount > 0, "Attempting to wait on a semaphore with zero ref count"); int ret; if (aWaitTime.isSome()) { struct timespec ts; if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { returnfalse;
}
¤ 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.0.34Bemerkung:
(vorverarbeitet)
¤
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.