Bug 932076 - Add check for MediaExtractor creation failure. r=doublec
[gecko.git] / ipc / glue / CrossProcessMutex.h
blob7c48cdae4a08a9fa0d62b8e27ca347cbd3d6e2c2
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"
12 namespace IPC {
13 template<typename T>
14 struct ParamTraits;
18 // Provides:
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.
27 namespace mozilla {
28 #ifdef XP_WIN
29 typedef HANDLE CrossProcessMutexHandle;
30 #else
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;
34 #endif
36 class NS_COM_GLUE CrossProcessMutex
38 public:
39 /**
40 * CrossProcessMutex
41 * @param name A name which can reference this lock (currently unused)
42 **/
43 CrossProcessMutex(const char* aName);
44 /**
45 * CrossProcessMutex
46 * @param handle A handle of an existing cross process mutex that can be
47 * opened.
49 CrossProcessMutex(CrossProcessMutexHandle aHandle);
51 /**
52 * ~CrossProcessMutex
53 **/
54 ~CrossProcessMutex();
56 /**
57 * Lock
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
63 * released.
64 **/
65 void Lock();
67 /**
68 * Unlock
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
72 * execution.
73 **/
74 void Unlock();
76 /**
77 * ShareToProcess
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);
85 private:
86 friend struct IPC::ParamTraits<CrossProcessMutex>;
88 CrossProcessMutex();
89 CrossProcessMutex(const CrossProcessMutex&);
90 CrossProcessMutex &operator=(const CrossProcessMutex&);
92 #ifdef XP_WIN
93 HANDLE mMutex;
94 #endif
97 typedef BaseAutoLock<CrossProcessMutex> CrossProcessMutexAutoLock;
98 typedef BaseAutoUnlock<CrossProcessMutex> CrossProcessMutexAutoUnlock;
101 #endif