summaryrefslogtreecommitdiffstats
path: root/xpcom/build/IOInterposerPrivate.h
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /xpcom/build/IOInterposerPrivate.h
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'xpcom/build/IOInterposerPrivate.h')
-rw-r--r--xpcom/build/IOInterposerPrivate.h167
1 files changed, 167 insertions, 0 deletions
diff --git a/xpcom/build/IOInterposerPrivate.h b/xpcom/build/IOInterposerPrivate.h
new file mode 100644
index 000000000..549321062
--- /dev/null
+++ b/xpcom/build/IOInterposerPrivate.h
@@ -0,0 +1,167 @@
+/* -*- 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/. */
+
+#ifndef xpcom_build_IOInterposerPrivate_h
+#define xpcom_build_IOInterposerPrivate_h
+
+/* This header file contains declarations for helper classes that are
+ to be used exclusively by IOInterposer and its observers. This header
+ file is not to be used by anything else and MUST NOT be exported! */
+
+#include <prcvar.h>
+#include <prlock.h>
+
+namespace mozilla {
+namespace IOInterposer {
+
+/**
+ * The following classes are simple wrappers for PRLock and PRCondVar.
+ * IOInterposer and friends use these instead of Mozilla::Mutex et al because
+ * of the fact that IOInterposer is permitted to run until the process
+ * terminates; we can't use anything that plugs into leak checkers or deadlock
+ * detectors because IOInterposer will outlive those and generate false
+ * positives.
+ */
+
+class Monitor
+{
+public:
+ Monitor()
+ : mLock(PR_NewLock())
+ , mCondVar(PR_NewCondVar(mLock))
+ {
+ }
+
+ ~Monitor()
+ {
+ PR_DestroyCondVar(mCondVar);
+ mCondVar = nullptr;
+ PR_DestroyLock(mLock);
+ mLock = nullptr;
+ }
+
+ void Lock()
+ {
+ PR_Lock(mLock);
+ }
+
+ void Unlock()
+ {
+ PR_Unlock(mLock);
+ }
+
+ bool Wait(PRIntervalTime aTimeout = PR_INTERVAL_NO_TIMEOUT)
+ {
+ return PR_WaitCondVar(mCondVar, aTimeout) == PR_SUCCESS;
+ }
+
+ bool Notify()
+ {
+ return PR_NotifyCondVar(mCondVar) == PR_SUCCESS;
+ }
+
+private:
+ PRLock* mLock;
+ PRCondVar* mCondVar;
+};
+
+class MonitorAutoLock
+{
+public:
+ explicit MonitorAutoLock(Monitor& aMonitor)
+ : mMonitor(aMonitor)
+ {
+ mMonitor.Lock();
+ }
+
+ ~MonitorAutoLock()
+ {
+ mMonitor.Unlock();
+ }
+
+ bool Wait(PRIntervalTime aTimeout = PR_INTERVAL_NO_TIMEOUT)
+ {
+ return mMonitor.Wait(aTimeout);
+ }
+
+ bool Notify()
+ {
+ return mMonitor.Notify();
+ }
+
+private:
+ Monitor& mMonitor;
+};
+
+class MonitorAutoUnlock
+{
+public:
+ explicit MonitorAutoUnlock(Monitor& aMonitor)
+ : mMonitor(aMonitor)
+ {
+ mMonitor.Unlock();
+ }
+
+ ~MonitorAutoUnlock()
+ {
+ mMonitor.Lock();
+ }
+
+private:
+ Monitor& mMonitor;
+};
+
+class Mutex
+{
+public:
+ Mutex()
+ : mPRLock(PR_NewLock())
+ {
+ }
+
+ ~Mutex()
+ {
+ PR_DestroyLock(mPRLock);
+ mPRLock = nullptr;
+ }
+
+ void Lock()
+ {
+ PR_Lock(mPRLock);
+ }
+
+ void Unlock()
+ {
+ PR_Unlock(mPRLock);
+ }
+
+private:
+ PRLock* mPRLock;
+};
+
+class AutoLock
+{
+public:
+ explicit AutoLock(Mutex& aLock)
+ : mLock(aLock)
+ {
+ mLock.Lock();
+ }
+
+ ~AutoLock()
+ {
+ mLock.Unlock();
+ }
+
+private:
+ Mutex& mLock;
+};
+
+} // namespace IOInterposer
+} // namespace mozilla
+
+#endif // xpcom_build_IOInterposerPrivate_h
+