StaticPrefsBase.h (2474B)
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/. */ 6 7 #ifndef mozilla_StaticPrefsBase_h 8 #define mozilla_StaticPrefsBase_h 9 10 #include <type_traits> 11 12 #include "mozilla/Atomics.h" 13 #include "mozilla/DataMutex.h" 14 #include "nsString.h" 15 16 namespace mozilla { 17 18 class SharedPrefMapBuilder; 19 20 // These typedefs are for use within init/StaticPrefList*.h. 21 22 typedef const char* String; 23 24 using DataMutexString = StaticDataMutex<nsCString>; 25 26 template <typename T> 27 struct IsString : std::false_type {}; 28 29 template <> 30 struct IsString<String> : std::true_type {}; 31 32 template <> 33 struct IsString<DataMutexString> : std::true_type {}; 34 35 typedef Atomic<bool, Relaxed> RelaxedAtomicBool; 36 typedef Atomic<bool, ReleaseAcquire> ReleaseAcquireAtomicBool; 37 typedef Atomic<bool, SequentiallyConsistent> SequentiallyConsistentAtomicBool; 38 39 typedef Atomic<int32_t, Relaxed> RelaxedAtomicInt32; 40 typedef Atomic<int32_t, ReleaseAcquire> ReleaseAcquireAtomicInt32; 41 typedef Atomic<int32_t, SequentiallyConsistent> 42 SequentiallyConsistentAtomicInt32; 43 44 typedef Atomic<uint32_t, Relaxed> RelaxedAtomicUint32; 45 typedef Atomic<uint32_t, ReleaseAcquire> ReleaseAcquireAtomicUint32; 46 typedef Atomic<uint32_t, SequentiallyConsistent> 47 SequentiallyConsistentAtomicUint32; 48 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; 52 53 template <typename T> 54 struct StripAtomicImpl { 55 typedef T Type; 56 }; 57 58 template <typename T, MemoryOrdering Order> 59 struct StripAtomicImpl<Atomic<T, Order>> { 60 typedef T Type; 61 }; 62 63 template <typename T> 64 struct StripAtomicImpl<std::atomic<T>> { 65 typedef T Type; 66 }; 67 68 template <> 69 struct StripAtomicImpl<DataMutexString> { 70 typedef nsCString Type; 71 }; 72 73 template <typename T> 74 using StripAtomic = typename StripAtomicImpl<T>::Type; 75 76 template <typename T> 77 struct IsAtomic : std::false_type {}; 78 79 template <typename T, MemoryOrdering Order> 80 struct IsAtomic<Atomic<T, Order>> : std::true_type {}; 81 82 template <typename T> 83 struct IsAtomic<std::atomic<T>> : std::true_type {}; 84 85 namespace StaticPrefs { 86 87 void MaybeInitOncePrefs(); 88 89 } // namespace StaticPrefs 90 91 } // namespace mozilla 92 93 #endif // mozilla_StaticPrefsBase_h