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"
18 class SharedPrefMapBuilder
;
20 // These typedefs are for use within init/StaticPrefList*.h.
22 typedef const char* String
;
24 using DataMutexString
= StaticDataMutex
<nsCString
>;
27 struct IsString
: std::false_type
{};
30 struct IsString
<String
> : std::true_type
{};
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
;
54 struct StripAtomicImpl
{
58 template <typename T
, MemoryOrdering Order
>
59 struct StripAtomicImpl
<Atomic
<T
, Order
>> {
64 struct StripAtomicImpl
<std::atomic
<T
>> {
69 struct StripAtomicImpl
<DataMutexString
> {
70 typedef nsCString Type
;
74 using StripAtomic
= typename StripAtomicImpl
<T
>::Type
;
77 struct IsAtomic
: std::false_type
{};
79 template <typename T
, MemoryOrdering Order
>
80 struct IsAtomic
<Atomic
<T
, Order
>> : std::true_type
{};
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