зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1732343 - Part 7: Use attached handles for Windows CrossProcess{Mutex,Semaphore} serialization, r=handyman
Differential Revision: https://phabricator.services.mozilla.com/D126569
This commit is contained in:
Родитель
71d0301a3c
Коммит
f3e5fa0fee
|
@ -10,6 +10,9 @@
|
|||
#include "base/process.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
# include "mozilla/UniquePtrExtensions.h"
|
||||
#endif
|
||||
#if !defined(OS_WIN) && !defined(OS_NETBSD) && !defined(OS_OPENBSD)
|
||||
# include <pthread.h>
|
||||
# include "mozilla/ipc/SharedMemoryBasic.h"
|
||||
|
@ -34,7 +37,7 @@ struct ParamTraits;
|
|||
//
|
||||
namespace mozilla {
|
||||
#if defined(OS_WIN)
|
||||
typedef HANDLE CrossProcessMutexHandle;
|
||||
typedef mozilla::UniqueFileHandle CrossProcessMutexHandle;
|
||||
#elif !defined(OS_NETBSD) && !defined(OS_OPENBSD)
|
||||
typedef mozilla::ipc::SharedMemoryBasic::Handle CrossProcessMutexHandle;
|
||||
#else
|
||||
|
|
|
@ -30,10 +30,10 @@ CrossProcessMutex::CrossProcessMutex(const char*) {
|
|||
|
||||
CrossProcessMutex::CrossProcessMutex(CrossProcessMutexHandle aHandle) {
|
||||
DWORD flags;
|
||||
if (!::GetHandleInformation(aHandle, &flags)) {
|
||||
if (!::GetHandleInformation(aHandle.get(), &flags)) {
|
||||
MOZ_CRASH("Attempt to construct a mutex from an invalid handle!");
|
||||
}
|
||||
mMutex = aHandle;
|
||||
mMutex = aHandle.release();
|
||||
MOZ_COUNT_CTOR(CrossProcessMutex);
|
||||
}
|
||||
|
||||
|
@ -56,14 +56,11 @@ void CrossProcessMutex::Unlock() {
|
|||
CrossProcessMutexHandle CrossProcessMutex::ShareToProcess(
|
||||
base::ProcessId aTargetPid) {
|
||||
HANDLE newHandle;
|
||||
bool succeeded = ipc::DuplicateHandle(mMutex, aTargetPid, &newHandle, 0,
|
||||
DUPLICATE_SAME_ACCESS);
|
||||
|
||||
if (!succeeded) {
|
||||
if (!::DuplicateHandle(GetCurrentProcess(), mMutex, GetCurrentProcess(),
|
||||
&newHandle, 0, false, DUPLICATE_SAME_ACCESS)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return newHandle;
|
||||
return mozilla::UniqueFileHandle(newHandle);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
# include "mozilla/UniquePtrExtensions.h"
|
||||
#endif
|
||||
#if !defined(OS_WIN) && !defined(OS_MACOSX)
|
||||
# include <pthread.h>
|
||||
# include <semaphore.h>
|
||||
|
@ -35,7 +38,7 @@ inline bool IsHandleValid(const T& handle) {
|
|||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
typedef HANDLE CrossProcessSemaphoreHandle;
|
||||
typedef mozilla::UniqueFileHandle CrossProcessSemaphoreHandle;
|
||||
#elif !defined(OS_MACOSX)
|
||||
typedef mozilla::ipc::SharedMemoryBasic::Handle CrossProcessSemaphoreHandle;
|
||||
|
||||
|
|
|
@ -35,11 +35,11 @@ CrossProcessSemaphore* CrossProcessSemaphore::Create(const char*,
|
|||
CrossProcessSemaphore* CrossProcessSemaphore::Create(
|
||||
CrossProcessSemaphoreHandle aHandle) {
|
||||
DWORD flags;
|
||||
if (!::GetHandleInformation(aHandle, &flags)) {
|
||||
if (!::GetHandleInformation(aHandle.get(), &flags)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new CrossProcessSemaphore(aHandle);
|
||||
return new CrossProcessSemaphore(aHandle.release());
|
||||
}
|
||||
|
||||
CrossProcessSemaphore::CrossProcessSemaphore(HANDLE aSemaphore)
|
||||
|
@ -68,14 +68,15 @@ void CrossProcessSemaphore::Signal() {
|
|||
CrossProcessSemaphoreHandle CrossProcessSemaphore::ShareToProcess(
|
||||
base::ProcessId aTargetPid) {
|
||||
HANDLE newHandle;
|
||||
bool succeeded = ipc::DuplicateHandle(mSemaphore, aTargetPid, &newHandle, 0,
|
||||
DUPLICATE_SAME_ACCESS);
|
||||
bool succeeded =
|
||||
::DuplicateHandle(GetCurrentProcess(), mSemaphore, GetCurrentProcess(),
|
||||
&newHandle, 0, false, DUPLICATE_SAME_ACCESS);
|
||||
|
||||
if (!succeeded) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return newHandle;
|
||||
return UniqueFileHandle(newHandle);
|
||||
}
|
||||
|
||||
void CrossProcessSemaphore::CloseHandle() {}
|
||||
|
|
Загрузка…
Ссылка в новой задаче