piranha  0.10
init_data.hpp
1 /* Copyright 2009-2017 Francesco Biscani (bluescarni@gmail.com)
2 
3 This file is part of the Piranha library.
4 
5 The Piranha library is free software; you can redistribute it and/or modify
6 it under the terms of either:
7 
8  * the GNU Lesser General Public License as published by the Free
9  Software Foundation; either version 3 of the License, or (at your
10  option) any later version.
11 
12 or
13 
14  * the GNU General Public License as published by the Free Software
15  Foundation; either version 3 of the License, or (at your option) any
16  later version.
17 
18 or both in parallel, as here.
19 
20 The Piranha library is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24 
25 You should have received copies of the GNU General Public License and the
26 GNU Lesser General Public License along with the Piranha library. If not,
27 see https://www.gnu.org/licenses/. */
28 
29 #ifndef PIRANHA_DETAIL_INIT_DATA_HPP
30 #define PIRANHA_DETAIL_INIT_DATA_HPP
31 
32 #include <atomic>
33 
34 namespace piranha
35 {
36 
37 inline namespace impl
38 {
39 
40 // Global variables for init/shutdown.
41 template <typename = void>
42 struct piranha_init_statics {
43  static std::atomic_flag s_init_flag;
44  static std::atomic<bool> s_shutdown_flag;
45  static std::atomic<unsigned> s_failed;
46 };
47 
48 // Static init of the global flags.
49 template <typename T>
50 std::atomic_flag piranha_init_statics<T>::s_init_flag = ATOMIC_FLAG_INIT;
51 
52 template <typename T>
53 std::atomic<bool> piranha_init_statics<T>::s_shutdown_flag(false);
54 
55 template <typename T>
56 std::atomic<unsigned> piranha_init_statics<T>::s_failed(0u);
57 
58 // Query if we are at shutdown.
59 inline bool shutdown()
60 {
61  return piranha_init_statics<>::s_shutdown_flag.load();
62 }
63 }
64 }
65 
66 #endif
Root piranha namespace.
Definition: array_key.hpp:52