diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /ipc/chromium/src/chrome/common/ipc_channel_capability.h | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ipc/chromium/src/chrome/common/ipc_channel_capability.h')
-rw-r--r-- | ipc/chromium/src/chrome/common/ipc_channel_capability.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ipc/chromium/src/chrome/common/ipc_channel_capability.h b/ipc/chromium/src/chrome/common/ipc_channel_capability.h new file mode 100644 index 0000000000..c23f16e577 --- /dev/null +++ b/ipc/chromium/src/chrome/common/ipc_channel_capability.h @@ -0,0 +1,61 @@ +/* -*- 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 CHROME_COMMON_IPC_CHANNEL_CAPABILITY_H_ +#define CHROME_COMMON_IPC_CHANNEL_CAPABILITY_H_ + +#include "mozilla/ThreadSafety.h" +#include "mozilla/Mutex.h" +#include "mozilla/EventTargetCapability.h" +#include "nsISerialEventTarget.h" + +namespace IPC { + +// A thread-safety capability used in IPC channel implementations. Combines an +// EventTargetCapability and a Mutex to allow using each independently, as well +// as combined together. +// +// The ChannelCapability grants shared access if on the IOThread or if the send +// mutex is held, and only allows exclusive access if both on the IO thread and +// holding the send mutex. This is similar to a `MutexSingleWriter`, but more +// flexible due to providing access to each sub-capability. +class MOZ_CAPABILITY("channel cap") ChannelCapability { + public: + using Mutex = mozilla::Mutex; + using Thread = mozilla::EventTargetCapability<nsISerialEventTarget>; + + ChannelCapability(const char* mutex_name, nsISerialEventTarget* io_thread) + : send_mutex_(mutex_name), io_thread_(io_thread) {} + + const Thread& IOThread() const MOZ_RETURN_CAPABILITY(io_thread_) { + return io_thread_; + } + Mutex& SendMutex() MOZ_RETURN_CAPABILITY(send_mutex_) { return send_mutex_; } + + // Note that we're on the IO thread, and thus have shared access to values + // guarded by the channel capability for the thread-safety analysis. + void NoteOnIOThread() const MOZ_REQUIRES(io_thread_) + MOZ_ASSERT_SHARED_CAPABILITY(this) {} + + // Note that we're holding the send mutex, and thus have shared access to + // values guarded by the channel capability for the thread-safety analysis. + void NoteSendMutex() const MOZ_REQUIRES(send_mutex_) + MOZ_ASSERT_SHARED_CAPABILITY(this) {} + + // Note that we're holding the send mutex while on the IO thread, and thus + // have exclusive access to values guarded by the channel capability for the + // thread-safety analysis. + void NoteExclusiveAccess() const MOZ_REQUIRES(io_thread_, send_mutex_) + MOZ_ASSERT_CAPABILITY(this) {} + + private: + mozilla::Mutex send_mutex_; + mozilla::EventTargetCapability<nsISerialEventTarget> io_thread_; +}; + +} // namespace IPC + +#endif // CHROME_COMMON_IPC_CHANNEL_CAPABILITY_H_ |