/* -*- 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 mozilla_StaticPrefs_h #define mozilla_StaticPrefs_h #include "mozilla/Assertions.h" #include "mozilla/Atomics.h" #include "mozilla/TypeTraits.h" #include "MainThreadUtils.h" namespace mozilla { // These typedefs are for use within StaticPrefList.h. typedef const char* String; typedef Atomic RelaxedAtomicBool; typedef Atomic ReleaseAcquireAtomicBool; typedef Atomic SequentiallyConsistentAtomicBool; typedef Atomic RelaxedAtomicInt32; typedef Atomic ReleaseAcquireAtomicInt32; typedef Atomic SequentiallyConsistentAtomicInt32; typedef Atomic RelaxedAtomicUint32; typedef Atomic ReleaseAcquireAtomicUint32; typedef Atomic SequentiallyConsistentAtomicUint32; template struct StripAtomicImpl { typedef T Type; }; template struct StripAtomicImpl> { typedef T Type; }; template using StripAtomic = typename StripAtomicImpl::Type; template struct IsAtomic : FalseType { }; template struct IsAtomic> : TrueType { }; class StaticPrefs { // For a VarCache pref like this: // // VARCACHE_PREF("my.varcache", my_varcache, int32_t, 99) // // we generate a static variable declaration and a getter definition: // // private: // static int32_t sVarCache_my_varcache; // public: // static int32_t my_varcache() { return sVarCache_my_varcache; } // #define PREF(str, cpp_type, default_value) #define VARCACHE_PREF(str, id, cpp_type, default_value) \ private: \ static cpp_type sVarCache_##id; \ \ public: \ static StripAtomic id() \ { \ MOZ_ASSERT(IsAtomic::value || NS_IsMainThread(), \ "Non-atomic static pref '" str \ "' being accessed on background thread"); \ return sVarCache_##id; \ } #include "mozilla/StaticPrefList.h" #undef PREF #undef VARCACHE_PREF public: static void InitAll(bool aIsStartup); }; } // namespace mozilla #endif // mozilla_StaticPrefs_h