1 | /* |
---|---|
2 | * Copyright Andrey Semashev 2007 - 2015. |
3 | * Distributed under the Boost Software License, Version 1.0. |
4 | * (See accompanying file LICENSE_1_0.txt or copy at |
5 | * http://www.boost.org/LICENSE_1_0.txt) |
6 | */ |
7 | /*! |
8 | * \file severity_level.cpp |
9 | * \author Andrey Semashev |
10 | * \date 10.05.2008 |
11 | * |
12 | * \brief This header is the Boost.Log library implementation, see the library documentation |
13 | * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. |
14 | */ |
15 | |
16 | #include <boost/log/detail/config.hpp> |
17 | #include <boost/cstdint.hpp> |
18 | #include <boost/log/sources/severity_feature.hpp> |
19 | |
20 | #if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_LOG_USE_COMPILER_TLS) |
21 | #include <boost/thread/thread.hpp> // at_thread_exit |
22 | #include <boost/log/detail/singleton.hpp> |
23 | #include <boost/log/detail/thread_specific.hpp> |
24 | #endif |
25 | #include "unique_ptr.hpp" |
26 | #include <boost/log/detail/header.hpp> |
27 | |
28 | namespace boost { |
29 | |
30 | BOOST_LOG_OPEN_NAMESPACE |
31 | |
32 | namespace sources { |
33 | |
34 | namespace aux { |
35 | |
36 | #if defined(BOOST_LOG_NO_THREADS) |
37 | |
38 | static uintmax_t g_Severity = 0; |
39 | |
40 | #elif defined(BOOST_LOG_USE_COMPILER_TLS) |
41 | |
42 | static BOOST_LOG_TLS uintmax_t g_Severity = 0; |
43 | |
44 | #else |
45 | |
46 | //! Severity level storage class |
47 | class severity_level_holder : |
48 | public boost::log::aux::lazy_singleton< severity_level_holder, boost::log::aux::thread_specific< uintmax_t* > > |
49 | { |
50 | }; |
51 | |
52 | #endif |
53 | |
54 | |
55 | #if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_LOG_USE_COMPILER_TLS) |
56 | |
57 | //! The method returns the severity level for the current thread |
58 | BOOST_LOG_API uintmax_t& get_severity_level() |
59 | { |
60 | boost::log::aux::thread_specific< uintmax_t* >& tss = severity_level_holder::get(); |
61 | uintmax_t* p = tss.get(); |
62 | if (BOOST_UNLIKELY(!p)) |
63 | { |
64 | log::aux::unique_ptr< uintmax_t > ptr(new uintmax_t(0)); |
65 | tss.set(ptr.get()); |
66 | p = ptr.release(); |
67 | boost::this_thread::at_thread_exit(f: [p]() { delete p; }); |
68 | } |
69 | return *p; |
70 | } |
71 | |
72 | #else // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_LOG_USE_COMPILER_TLS) |
73 | |
74 | //! The method returns the severity level for the current thread |
75 | BOOST_LOG_API uintmax_t& get_severity_level() |
76 | { |
77 | return g_Severity; |
78 | } |
79 | |
80 | #endif // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_LOG_USE_COMPILER_TLS) |
81 | |
82 | } // namespace aux |
83 | |
84 | } // namespace sources |
85 | |
86 | BOOST_LOG_CLOSE_NAMESPACE // namespace log |
87 | |
88 | } // namespace boost |
89 | |
90 | #include <boost/log/detail/footer.hpp> |
91 |