Backed out changeset 5f819082a015 (bug 1936189) for causing reftest failures @ native...
[gecko.git] / modules / libpref / StaticPrefsBase.h
blob597a5beda2cb7e83fab90aafc3bf7bafa0937f15
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_StaticPrefsBase_h
8 #define mozilla_StaticPrefsBase_h
10 #include <type_traits>
12 #include "mozilla/Atomics.h"
13 #include "mozilla/DataMutex.h"
14 #include "nsString.h"
16 namespace mozilla {
18 class SharedPrefMapBuilder;
20 // These typedefs are for use within init/StaticPrefList*.h.
22 typedef const char* String;
24 using DataMutexString = StaticDataMutex<nsCString>;
26 template <typename T>
27 struct IsString : std::false_type {};
29 template <>
30 struct IsString<String> : std::true_type {};
32 template <>
33 struct IsString<DataMutexString> : std::true_type {};
35 typedef Atomic<bool, Relaxed> RelaxedAtomicBool;
36 typedef Atomic<bool, ReleaseAcquire> ReleaseAcquireAtomicBool;
37 typedef Atomic<bool, SequentiallyConsistent> SequentiallyConsistentAtomicBool;
39 typedef Atomic<int32_t, Relaxed> RelaxedAtomicInt32;
40 typedef Atomic<int32_t, ReleaseAcquire> ReleaseAcquireAtomicInt32;
41 typedef Atomic<int32_t, SequentiallyConsistent>
42 SequentiallyConsistentAtomicInt32;
44 typedef Atomic<uint32_t, Relaxed> RelaxedAtomicUint32;
45 typedef Atomic<uint32_t, ReleaseAcquire> ReleaseAcquireAtomicUint32;
46 typedef Atomic<uint32_t, SequentiallyConsistent>
47 SequentiallyConsistentAtomicUint32;
49 // XXX: Atomic<float> currently doesn't work (see bug 1552086). Once it's
50 // supported we will be able to use Atomic<float> here.
51 typedef std::atomic<float> AtomicFloat;
53 template <typename T>
54 struct StripAtomicImpl {
55 typedef T Type;
58 template <typename T, MemoryOrdering Order>
59 struct StripAtomicImpl<Atomic<T, Order>> {
60 typedef T Type;
63 template <typename T>
64 struct StripAtomicImpl<std::atomic<T>> {
65 typedef T Type;
68 template <>
69 struct StripAtomicImpl<DataMutexString> {
70 typedef nsCString Type;
73 template <typename T>
74 using StripAtomic = typename StripAtomicImpl<T>::Type;
76 template <typename T>
77 struct IsAtomic : std::false_type {};
79 template <typename T, MemoryOrdering Order>
80 struct IsAtomic<Atomic<T, Order>> : std::true_type {};
82 template <typename T>
83 struct IsAtomic<std::atomic<T>> : std::true_type {};
85 namespace StaticPrefs {
87 void MaybeInitOncePrefs();
89 } // namespace StaticPrefs
91 } // namespace mozilla
93 #endif // mozilla_StaticPrefsBase_h