diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-03 03:18:59 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-03 03:18:59 +0000 |
commit | e30ea1b12c8d7f66d53533c6596c62fc5890fcae (patch) | |
tree | 33f6743dbcd73e6ce828e62a1a9dd984f7ffb964 | |
parent | 1d1061c0488ed85f3d23b61b982d1bf84adab324 (diff) | |
download | ATCD-e30ea1b12c8d7f66d53533c6596c62fc5890fcae.tar.gz |
(VxWorks only): fixed used of ::taskDeleteHookAdd (it should only be called once for all Log_Msg instances) and added call to ::taskDeleteHookDelete to clean up when the last task exits
-rw-r--r-- | ace/Log_Msg.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/ace/Log_Msg.cpp b/ace/Log_Msg.cpp index 7f8983b8aab..6225d122630 100644 --- a/ace/Log_Msg.cpp +++ b/ace/Log_Msg.cpp @@ -71,6 +71,10 @@ public: static ACE_Thread_Mutex *get_lock (void); #if defined (VXWORKS) + // For keeping track of the number of tasks, so we know when to + // add or delete the task delete hook. + static u_int task_count_; + static void atexit (WIND_TCB *); #else static void atexit (void); @@ -84,13 +88,13 @@ public: private: static ACE_Thread_Mutex *lock_; +#if !defined (VXWORKS) // Holds a list of all <ACE_Log_Msg> instances. <instances_> // requires global construction/destruction. If that's a problem, // could change it to a pointer and allocate it dynamically when // lock_ is allocated. -#if !defined (VXWORKS) static ACE_Log_Msg_Set instances_; -#endif /* VXWORKS */ +#endif /* ! VXWORKS */ }; #if defined (ACE_HAS_SIG_C_FUNC) @@ -117,15 +121,24 @@ ACE_Log_Msg_Manager::get_lock (void) } #if defined (VXWORKS) +u_int ACE_Log_Msg_Manager::task_count_ = 0; + void ACE_Log_Msg_Manager::atexit (WIND_TCB *tcb) { - // The task is exiting, so its ACE_Log_Msg instance. + // The task is exiting, so delete its ACE_Log_Msg instance. delete (ACE_Log_Msg *) tcb->spare1; - // Ugly, ugly, but don't know a better way. - delete ACE_Log_Msg_Manager::lock_; - ACE_Log_Msg_Manager::lock_ = 0; + // If this is the last task to exit from the program, then delete the task + // delete hook. Also, delete the global lock_. + if (--task_count_ == 0) + { + ::taskDeleteHookDelete ((FUNCPTR) ACE_Log_Msg_Manager::atexit); + + // Ugly, ugly, but don't know a better way. + delete ACE_Log_Msg_Manager::lock_; + ACE_Log_Msg_Manager::lock_ = 0; + } } #else ACE_Log_Msg_Set ACE_Log_Msg_Manager::instances_; @@ -238,8 +251,11 @@ ACE_Log_Msg::instance (void) // thread-safe. ACE_Log_Msg_Manager::get_lock (); - // Register cleanup handler. - ::taskDeleteHookAdd ((FUNCPTR) ACE_Log_Msg_Manager::atexit); + if (ACE_Log_Msg_Manager::task_count_++ == 0) + { + // Register cleanup handler, just once, for all tasks. + ::taskDeleteHookAdd ((FUNCPTR) ACE_Log_Msg_Manager::atexit); + } // Allocate memory off the heap and store it in a pointer in // thread-specific storage, i.e., in the task control block. |