• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/bind/bind.hpp>
22 #include <boost/checked_delete.hpp>
23 #include <boost/thread/thread.hpp> // at_thread_exit
24 #include <boost/log/detail/singleton.hpp>
25 #include <boost/log/detail/thread_specific.hpp>
26 #endif
27 #include "unique_ptr.hpp"
28 #include <boost/log/detail/header.hpp>
29 
30 namespace boost {
31 
32 BOOST_LOG_OPEN_NAMESPACE
33 
34 namespace sources {
35 
36 namespace aux {
37 
38 #if defined(BOOST_LOG_NO_THREADS)
39 
40 static uintmax_t g_Severity = 0;
41 
42 #elif defined(BOOST_LOG_USE_COMPILER_TLS)
43 
44 static BOOST_LOG_TLS uintmax_t g_Severity = 0;
45 
46 #else
47 
48 //! Severity level storage class
49 class severity_level_holder :
50     public boost::log::aux::lazy_singleton< severity_level_holder, boost::log::aux::thread_specific< uintmax_t* > >
51 {
52 };
53 
54 #endif
55 
56 
57 #if !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_LOG_USE_COMPILER_TLS)
58 
59 //! The method returns the severity level for the current thread
get_severity_level()60 BOOST_LOG_API uintmax_t& get_severity_level()
61 {
62     boost::log::aux::thread_specific< uintmax_t* >& tss = severity_level_holder::get();
63     uintmax_t* p = tss.get();
64     if (BOOST_UNLIKELY(!p))
65     {
66         log::aux::unique_ptr< uintmax_t > ptr(new uintmax_t(0));
67         tss.set(ptr.get());
68         p = ptr.release();
69         boost::this_thread::at_thread_exit(boost::bind(checked_deleter< uintmax_t >(), p));
70     }
71     return *p;
72 }
73 
74 #else // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_LOG_USE_COMPILER_TLS)
75 
76 //! The method returns the severity level for the current thread
get_severity_level()77 BOOST_LOG_API uintmax_t& get_severity_level()
78 {
79     return g_Severity;
80 }
81 
82 #endif // !defined(BOOST_LOG_NO_THREADS) && !defined(BOOST_LOG_USE_COMPILER_TLS)
83 
84 } // namespace aux
85 
86 } // namespace sources
87 
88 BOOST_LOG_CLOSE_NAMESPACE // namespace log
89 
90 } // namespace boost
91 
92 #include <boost/log/detail/footer.hpp>
93