GitHub Actions: Try MSVC builds with /std:c++17 and 20
[ACE_TAO.git] / ACE / ace / Log_Category.cpp
blob98a2cc8585a8ec27c46c4082156148ab30bf87fa
1 #include "ace/Log_Msg.h"
2 #include "ace/Log_Category.h"
3 #include "ace/Atomic_Op.h"
4 #include "ace/OS_NS_Thread.h"
6 #if !defined (__ACE_INLINE__)
7 #include "ace/Log_Category.inl"
8 #endif /* __ACE_INLINE__ */
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 #if defined (ACE_HAS_THREADS)
13 extern "C" void
14 ACE_Log_Category_tss_destroy(void * p)
16 delete static_cast<ACE_Log_Category_TSS*>(p);
18 #endif // defined (ACE_HAS_THREADS)
20 ACE_Log_Category::ACE_Log_Category(const char* name)
21 : name_(name)
22 , id_(0)
23 /// Default per-process priority mask
24 /// By default, all priorities are enabled.
25 , priority_mask_(LM_SHUTDOWN
26 | LM_TRACE
27 | LM_DEBUG
28 | LM_INFO
29 | LM_NOTICE
30 | LM_WARNING
31 | LM_STARTUP
32 | LM_ERROR
33 | LM_CRITICAL
34 | LM_ALERT
35 | LM_EMERGENCY)
36 #if defined (ACE_HAS_THREADS)
37 , key_(ACE_OS::NULL_key)
38 #else
39 , per_thr_obj_(this, 0)
40 #endif
44 ACE_Log_Category::~ACE_Log_Category()
46 #if defined (ACE_HAS_THREADS)
47 ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->keylock_);
49 if (this->id_ > 0)
51 void *temp = 0;
52 if (ACE_OS::thr_getspecific (this->key_, &temp) == -1)
54 return; // This should not happen!
56 if (temp != 0) {
57 delete static_cast <ACE_Log_Category_TSS *> (temp);
58 ACE_OS::thr_setspecific (this->key_, 0);
60 ACE_OS::thr_keyfree (this->key_);
62 #endif
65 ACE_Log_Category_TSS::ACE_Log_Category_TSS(ACE_Log_Category* category, ACE_Log_Msg* logger)
66 : category_(category)
67 , logger_(logger)
68 , priority_mask_(0)
72 ACE_ALLOC_HOOK_DEFINE(ACE_Log_Category_TSS)
74 ACE_Log_Category_TSS*
75 ACE_Log_Category::per_thr_obj()
77 #if defined (ACE_HAS_THREADS)
79 // Ensure that we are serialized!
80 ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->keylock_, 0);
82 // make sure we only create the key once!
83 if (this->id_ == 0)
85 static ACE_Atomic_Op<ACE_Thread_Mutex, unsigned int> log_category_id_assigner(1);
86 id_ = log_category_id_assigner++; // for atomic integers, post increment is more efficient
88 if (ACE_OS::thr_keycreate (&this->key_,
89 &ACE_Log_Category_tss_destroy) != 0)
90 return 0; // Major problems, this should *never* happen!
94 void *temp = 0;
95 if (ACE_OS::thr_getspecific (this->key_, &temp) == -1)
97 return 0; // This should not happen!
99 if (temp != 0)
100 return static_cast <ACE_Log_Category_TSS *> (temp);
102 ACE_Log_Category_TSS * result;
104 ACE_NEW_RETURN(result,
105 ACE_Log_Category_TSS(this, ACE_Log_Msg::instance()),
108 if (ACE_OS::thr_setspecific (this->key_,
109 result) != 0)
111 return 0;
114 return result;
115 #else // defined (ACE_HAS_THREADS)
116 if (this->id_ == 0) {
117 static unsigned int log_category_id_assigner = 0;
118 id_ = log_category_id_assigner++;
119 per_thr_obj_.logger_ = ACE_Log_Msg::instance();
121 return &per_thr_obj_;
122 #endif // defined (ACE_HAS_THREADS)
125 ACE_Log_Category&
126 ACE_Log_Category::ace_lib()
128 static ACE_Log_Category ace_lib_category("ACE");
129 return ace_lib_category;
132 ACE_END_VERSIONED_NAMESPACE_DECL