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)
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
)
23 /// Default per-process priority mask
24 /// By default, all priorities are enabled.
25 , priority_mask_(LM_SHUTDOWN
36 #if defined (ACE_HAS_THREADS)
37 , key_(ACE_OS::NULL_key
)
39 , per_thr_obj_(this, 0)
44 ACE_Log_Category::~ACE_Log_Category()
46 #if defined (ACE_HAS_THREADS)
47 ACE_GUARD (ACE_Thread_Mutex
, ace_mon
, this->keylock_
);
52 if (ACE_OS::thr_getspecific (this->key_
, &temp
) == -1)
54 return; // This should not happen!
57 delete static_cast <ACE_Log_Category_TSS
*> (temp
);
58 ACE_OS::thr_setspecific (this->key_
, 0);
60 ACE_OS::thr_keyfree (this->key_
);
65 ACE_Log_Category_TSS::ACE_Log_Category_TSS(ACE_Log_Category
* category
, ACE_Log_Msg
* logger
)
72 ACE_ALLOC_HOOK_DEFINE(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!
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!
95 if (ACE_OS::thr_getspecific (this->key_
, &temp
) == -1)
97 return 0; // This should not happen!
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_
,
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)
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