1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_CrossProcessMutex_h
7 #define mozilla_CrossProcessMutex_h
9 #include "base/process.h"
10 #include "mozilla/Mutex.h"
20 // - CrossProcessMutex, a non-recursive mutex that can be shared across processes
21 // - CrossProcessMutexAutoLock, an RAII class for ensuring that Mutexes are
22 // properly locked and unlocked
24 // Using CrossProcessMutexAutoLock/CrossProcessMutexAutoUnlock is MUCH
25 // preferred to making bare calls to CrossProcessMutex.Lock and Unlock.
29 typedef HANDLE CrossProcessMutexHandle
;
31 // Stub for other platforms. We can't use uintptr_t here since different
32 // processes could disagree on its size.
33 typedef uintptr_t CrossProcessMutexHandle
;
36 class NS_COM_GLUE CrossProcessMutex
41 * @param name A name which can reference this lock (currently unused)
43 CrossProcessMutex(const char* aName
);
46 * @param handle A handle of an existing cross process mutex that can be
49 CrossProcessMutex(CrossProcessMutexHandle aHandle
);
58 * This will lock the mutex. Any other thread in any other process that
59 * has access to this mutex calling lock will block execution until the
60 * initial caller of lock has made a call to Unlock.
62 * If the owning process is terminated unexpectedly the mutex will be
69 * This will unlock the mutex. A single thread currently waiting on a lock
70 * call will resume execution and aquire ownership of the lock. No
71 * guarantees are made as to the order in which waiting threads will resume
78 * This function is called to generate a serializable structure that can
79 * be sent to the specified process and opened on the other side.
81 * @returns A handle that can be shared to another process
83 CrossProcessMutexHandle
ShareToProcess(base::ProcessHandle aTarget
);
86 friend struct IPC::ParamTraits
<CrossProcessMutex
>;
89 CrossProcessMutex(const CrossProcessMutex
&);
90 CrossProcessMutex
&operator=(const CrossProcessMutex
&);
97 typedef BaseAutoLock
<CrossProcessMutex
> CrossProcessMutexAutoLock
;
98 typedef BaseAutoUnlock
<CrossProcessMutex
> CrossProcessMutexAutoUnlock
;