summaryrefslogtreecommitdiffstats
path: root/dom/media/platforms/SimpleMap.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/media/platforms/SimpleMap.h
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/platforms/SimpleMap.h')
-rw-r--r--dom/media/platforms/SimpleMap.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/dom/media/platforms/SimpleMap.h b/dom/media/platforms/SimpleMap.h
new file mode 100644
index 0000000000..c26bff1e9a
--- /dev/null
+++ b/dom/media/platforms/SimpleMap.h
@@ -0,0 +1,55 @@
+/* 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 mozilla_SimpleMap_h
+#define mozilla_SimpleMap_h
+
+#include "mozilla/Mutex.h"
+#include "nsTArray.h"
+
+#include <utility>
+
+namespace mozilla {
+
+template <typename T>
+class SimpleMap {
+ public:
+ typedef std::pair<int64_t, T> Element;
+
+ SimpleMap() : mMutex("SimpleMap") {}
+
+ // Insert Key and Value pair at the end of our map.
+ void Insert(int64_t aKey, const T& aValue) {
+ MutexAutoLock lock(mMutex);
+ mMap.AppendElement(std::make_pair(aKey, aValue));
+ }
+ // Sets aValue matching aKey and remove it from the map if found.
+ // The element returned is the first one found.
+ // Returns true if found, false otherwise.
+ bool Find(int64_t aKey, T& aValue) {
+ MutexAutoLock lock(mMutex);
+ for (uint32_t i = 0; i < mMap.Length(); i++) {
+ Element& element = mMap[i];
+ if (element.first == aKey) {
+ aValue = element.second;
+ mMap.RemoveElementAt(i);
+ return true;
+ }
+ }
+ return false;
+ }
+ // Remove all elements of the map.
+ void Clear() {
+ MutexAutoLock lock(mMutex);
+ mMap.Clear();
+ }
+
+ private:
+ Mutex mMutex MOZ_UNANNOTATED; // To protect mMap.
+ AutoTArray<Element, 16> mMap;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_SimpleMap_h