Thread_Manager.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: Thread_Manager.inl 80826 2008-03-04 14:51:23Z wotte $
00004 
00005 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00006 
00007 ACE_INLINE
00008 ACE_At_Thread_Exit::ACE_At_Thread_Exit (void)
00009   : next_ (0),
00010     td_ (0),
00011     was_applied_ (0),
00012     is_owner_ (true)
00013 {
00014 }
00015 
00016 ACE_INLINE int
00017 ACE_At_Thread_Exit::was_applied() const
00018 
00019 {
00020    return was_applied_;
00021 }
00022 
00023 ACE_INLINE int
00024 ACE_At_Thread_Exit::was_applied (int applied)
00025 {
00026   was_applied_ = applied;
00027   if (was_applied_)
00028     td_ = 0;
00029   return was_applied_;
00030 }
00031 
00032 ACE_INLINE bool
00033 ACE_At_Thread_Exit::is_owner() const
00034 {
00035   return is_owner_;
00036 }
00037 
00038 ACE_INLINE bool
00039 ACE_At_Thread_Exit::is_owner (bool owner)
00040 {
00041   is_owner_ = owner;
00042   return is_owner_;
00043 }
00044 
00045 ACE_INLINE void
00046 ACE_At_Thread_Exit::do_apply (void)
00047 {
00048   if (!this->was_applied_ && this->is_owner_)
00049     td_->at_pop();
00050 }
00051 
00052 ACE_INLINE
00053 ACE_At_Thread_Exit_Func::ACE_At_Thread_Exit_Func (void *object,
00054                                                   ACE_CLEANUP_FUNC func,
00055                                                   void *param)
00056   : object_(object),
00057     func_(func),
00058     param_(param)
00059 {
00060 }
00061 
00062 ACE_INLINE
00063 ACE_Thread_Descriptor_Base::ACE_Thread_Descriptor_Base (void)
00064   : ACE_OS_Thread_Descriptor (),
00065     thr_id_ (ACE_OS::NULL_thread),
00066     thr_handle_ (ACE_OS::NULL_hthread),
00067     grp_id_ (0),
00068     thr_state_ (ACE_Thread_Manager::ACE_THR_IDLE),
00069     task_ (0),
00070     next_ (0),
00071     prev_ (0)
00072 {
00073 }
00074 
00075 ACE_INLINE
00076 ACE_Thread_Descriptor_Base::~ACE_Thread_Descriptor_Base (void)
00077 {
00078 }
00079 
00080 ACE_INLINE bool
00081 ACE_Thread_Descriptor_Base::operator== (
00082   const ACE_Thread_Descriptor_Base &rhs) const
00083 {
00084   return
00085     ACE_OS::thr_cmp (this->thr_handle_, rhs.thr_handle_)
00086     && ACE_OS::thr_equal (this->thr_id_, rhs.thr_id_);
00087 }
00088 
00089 ACE_INLINE bool
00090 ACE_Thread_Descriptor_Base::operator!=(const ACE_Thread_Descriptor_Base &rhs) const
00091 {
00092   return !(*this == rhs);
00093 }
00094 
00095 ACE_INLINE ACE_Task_Base *
00096 ACE_Thread_Descriptor_Base::task (void) const
00097 {
00098   ACE_TRACE ("ACE_Thread_Descriptor_Base::task");
00099   return this->task_;
00100 }
00101 
00102 // Group ID.
00103 
00104 ACE_INLINE int
00105 ACE_Thread_Descriptor_Base::grp_id (void) const
00106 {
00107   ACE_TRACE ("ACE_Thread_Descriptor_Base::grp_id");
00108   return grp_id_;
00109 }
00110 
00111 // Current state of the thread.
00112 ACE_INLINE ACE_UINT32
00113 ACE_Thread_Descriptor_Base::state (void) const
00114 {
00115   ACE_TRACE ("ACE_Thread_Descriptor_Base::state");
00116   return thr_state_;
00117 }
00118 
00119 // Reset this base descriptor.
00120 ACE_INLINE void
00121 ACE_Thread_Descriptor_Base::reset (void)
00122 {
00123   ACE_TRACE ("ACE_Thread_Descriptor_Base::reset");
00124   this->thr_id_ = ACE_OS::NULL_thread;
00125   this->thr_handle_ = ACE_OS::NULL_hthread;
00126   this->grp_id_ = 0;
00127   this->thr_state_ = ACE_Thread_Manager::ACE_THR_IDLE;
00128   this->task_ = 0;
00129   this->flags_ = 0;
00130 }
00131 
00132 // Unique thread id.
00133 ACE_INLINE ACE_thread_t
00134 ACE_Thread_Descriptor::self (void) const
00135 {
00136   ACE_TRACE ("ACE_Thread_Descriptor::self");
00137   return this->thr_id_;
00138 }
00139 
00140 // Unique kernel-level thread handle.
00141 
00142 ACE_INLINE void
00143 ACE_Thread_Descriptor::self (ACE_hthread_t &handle)
00144 {
00145   ACE_TRACE ("ACE_Thread_Descriptor::self");
00146   handle = this->thr_handle_;
00147 }
00148 
00149 ACE_INLINE void
00150 ACE_Thread_Descriptor::log_msg_cleanup (ACE_Log_Msg* log_msg)
00151 
00152 {
00153   log_msg_ = log_msg;
00154 }
00155 
00156 // Set the <next_> pointer
00157 ACE_INLINE void
00158 ACE_Thread_Descriptor::set_next (ACE_Thread_Descriptor *td)
00159 {
00160   ACE_TRACE ("ACE_Thread_Descriptor::set_next");
00161   this->next_ = td;
00162 }
00163 
00164 // Get the <next_> pointer
00165 ACE_INLINE ACE_Thread_Descriptor *
00166 ACE_Thread_Descriptor::get_next (void) const
00167 {
00168   ACE_TRACE ("ACE_Thread_Descriptor::get_next");
00169   return static_cast<ACE_Thread_Descriptor * ACE_CAST_CONST> (this->next_);
00170 }
00171 
00172 // Reset this thread descriptor
00173 ACE_INLINE void
00174 ACE_Thread_Descriptor::reset (ACE_Thread_Manager *tm)
00175 {
00176   ACE_TRACE ("ACE_Thread_Descriptor::reset");
00177   this->ACE_Thread_Descriptor_Base::reset ();
00178   this->at_exit_list_ = 0;
00179     // Start the at_exit hook list.
00180   this->tm_ = tm;
00181     // Setup the Thread_Manager.
00182   this->log_msg_ = 0;
00183   this->terminated_ = false;
00184 }
00185 
00186 ACE_INLINE ACE_Thread_Descriptor *
00187 ACE_Thread_Manager::thread_desc_self (void)
00188 {
00189   // This method must be called with lock held.
00190 
00191   // Try to get it from cache.
00192   ACE_Thread_Descriptor *desc = ACE_LOG_MSG->thr_desc ();
00193 
00194 #if 1
00195   //  ACE_ASSERT (desc != 0);
00196   // Thread descriptor should always get cached.
00197 #else
00198   if (desc == 0)
00199     {
00200       ACE_thread_t id = ACE_OS::thr_self ();
00201 
00202       desc = this->find_thread (id);
00203 
00204       // Thread descriptor adapter might not have been put into the
00205       // list yet.
00206       if (desc != 0)
00207         // Update the TSS cache.
00208         ACE_LOG_MSG->thr_desc (desc);
00209     }
00210 #endif
00211   return desc;
00212 }
00213 
00214 // Return the unique ID of the thread.
00215 
00216 ACE_INLINE ACE_thread_t
00217 ACE_Thread_Manager::thr_self (void)
00218 {
00219   ACE_TRACE ("ACE_Thread_Manager::thr_self");
00220   return ACE_Thread::self ();
00221 }
00222 
00223 ACE_INLINE ACE_Task_Base *
00224 ACE_Thread_Manager::task (void)
00225 {
00226   ACE_TRACE ("ACE_Thread_Manager::task");
00227 
00228   ACE_Thread_Descriptor *td = this->thread_desc_self () ;
00229 
00230   if (td == 0)
00231     return 0;
00232   else
00233     return td->task ();
00234 }
00235 
00236 ACE_INLINE int
00237 ACE_Thread_Manager::open (size_t)
00238 {
00239   // Currently no-op.
00240   return 0;
00241 }
00242 
00243 ACE_INLINE int
00244 ACE_Thread_Manager::at_exit (ACE_At_Thread_Exit* at)
00245 {
00246   ACE_Thread_Descriptor *td = this->thread_desc_self ();
00247   if (td == 0)
00248     return -1;
00249   else
00250     return td->at_exit (at);
00251 }
00252 
00253 ACE_INLINE int
00254 ACE_Thread_Manager::at_exit (ACE_At_Thread_Exit& at)
00255 {
00256   ACE_Thread_Descriptor *td = this->thread_desc_self ();
00257   if (td == 0)
00258     return -1;
00259   else
00260     return td->at_exit (at);
00261 }
00262 
00263 ACE_INLINE int
00264 ACE_Thread_Manager::at_exit (void *object,
00265                              ACE_CLEANUP_FUNC cleanup_hook,
00266                              void *param)
00267 {
00268   ACE_Thread_Descriptor *td = this->thread_desc_self ();
00269   if (td == 0)
00270     return -1;
00271   else
00272     return td->at_exit (object,
00273                         cleanup_hook,
00274                         param);
00275 }
00276 
00277 ACE_INLINE void
00278 ACE_Thread_Manager::wait_on_exit (int do_wait)
00279 {
00280   this->automatic_wait_ = do_wait;
00281 }
00282 
00283 ACE_INLINE int
00284 ACE_Thread_Manager::wait_on_exit (void)
00285 {
00286   return this->automatic_wait_;
00287 }
00288 
00289 ACE_INLINE int
00290 ACE_Thread_Manager::register_as_terminated (ACE_Thread_Descriptor *td)
00291 {
00292 #if defined (ACE_HAS_VXTHREADS)
00293   ACE_UNUSED_ARG (td);
00294 #else  /* ! ACE_HAS_VXTHREADS */
00295   ACE_Thread_Descriptor_Base *tdb = 0;
00296   ACE_NEW_RETURN (tdb, ACE_Thread_Descriptor_Base (*td), -1);
00297   this->terminated_thr_list_.insert_tail (tdb);
00298 #endif /* !ACE_HAS_VXTHREADS */
00299   return 0;
00300 }
00301 
00302 ACE_INLINE size_t
00303 ACE_Thread_Manager::count_threads (void) const
00304 {
00305   return this->thr_list_.size ();
00306 }
00307 
00308 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:43 2010 for ACE by  doxygen 1.4.7