00001
00002
00003
00004
00005
00006 #if !defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
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_ (1)
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 int
00033 ACE_At_Thread_Exit::is_owner() const
00034 {
00035 return is_owner_;
00036 }
00037
00038 ACE_INLINE int
00039 ACE_At_Thread_Exit::is_owner (int 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::~ACE_At_Thread_Exit (void)
00054 {
00055 this->do_apply ();
00056 }
00057
00058 ACE_INLINE
00059 ACE_At_Thread_Exit_Func::ACE_At_Thread_Exit_Func (void *object,
00060 ACE_CLEANUP_FUNC func,
00061 void *param)
00062 : object_(object),
00063 func_(func),
00064 param_(param)
00065 {
00066 }
00067
00068 ACE_INLINE
00069 ACE_At_Thread_Exit_Func::~ACE_At_Thread_Exit_Func (void)
00070 {
00071 this->do_apply ();
00072 }
00073
00074 ACE_INLINE void
00075 ACE_At_Thread_Exit_Func::apply ()
00076 {
00077 func_ (object_, param_);
00078 }
00079 #endif
00080
00081 ACE_INLINE
00082 ACE_Thread_Descriptor_Base::ACE_Thread_Descriptor_Base (void)
00083 : ACE_OS_Thread_Descriptor (),
00084 thr_id_ (ACE_OS::NULL_thread),
00085 thr_handle_ (ACE_OS::NULL_hthread),
00086 grp_id_ (0),
00087 thr_state_ (ACE_Thread_Manager::ACE_THR_IDLE),
00088 task_ (0),
00089 next_ (0),
00090 prev_ (0)
00091 {
00092 }
00093
00094 ACE_INLINE
00095 ACE_Thread_Descriptor_Base::~ACE_Thread_Descriptor_Base (void)
00096 {
00097 }
00098
00099 ACE_INLINE int
00100 ACE_Thread_Descriptor_Base::operator==(const ACE_Thread_Descriptor_Base &rhs) const
00101 {
00102 return ACE_OS::thr_cmp (this->thr_handle_, rhs.thr_handle_) == 0
00103 && ACE_OS::thr_equal (this->thr_id_, rhs.thr_id_) == 0;
00104 }
00105
00106 ACE_INLINE int
00107 ACE_Thread_Descriptor_Base::operator!=(const ACE_Thread_Descriptor_Base &rhs) const
00108 {
00109 return !(*this == rhs);
00110 }
00111
00112 ACE_INLINE ACE_Task_Base *
00113 ACE_Thread_Descriptor_Base::task (void) const
00114 {
00115 ACE_TRACE ("ACE_Thread_Descriptor_Base::task");
00116 return this->task_;
00117 }
00118
00119
00120
00121 ACE_INLINE int
00122 ACE_Thread_Descriptor_Base::grp_id (void) const
00123 {
00124 ACE_TRACE ("ACE_Thread_Descriptor_Base::grp_id");
00125 return grp_id_;
00126 }
00127
00128
00129 ACE_INLINE ACE_UINT32
00130 ACE_Thread_Descriptor_Base::state (void) const
00131 {
00132 ACE_TRACE ("ACE_Thread_Descriptor_Base::state");
00133 return thr_state_;
00134 }
00135
00136
00137 ACE_INLINE void
00138 ACE_Thread_Descriptor_Base::reset (void)
00139 {
00140 ACE_TRACE ("ACE_Thread_Descriptor_Base::reset");
00141 this->thr_id_ = ACE_OS::NULL_thread;
00142 this->thr_handle_ = ACE_OS::NULL_hthread;
00143 this->grp_id_ = 0;
00144 this->thr_state_ = ACE_Thread_Manager::ACE_THR_IDLE;
00145 this->task_ = 0;
00146 this->flags_ = 0;
00147 }
00148
00149
00150 ACE_INLINE ACE_thread_t
00151 ACE_Thread_Descriptor::self (void) const
00152 {
00153 ACE_TRACE ("ACE_Thread_Descriptor::self");
00154 return this->thr_id_;
00155 }
00156
00157
00158
00159 ACE_INLINE void
00160 ACE_Thread_Descriptor::self (ACE_hthread_t &handle)
00161 {
00162 ACE_TRACE ("ACE_Thread_Descriptor::self");
00163 handle = this->thr_handle_;
00164 }
00165
00166 #if !defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
00167 ACE_INLINE void
00168 ACE_Thread_Descriptor::log_msg_cleanup (ACE_Log_Msg* log_msg)
00169
00170 {
00171 log_msg_ = log_msg;
00172 }
00173 #endif
00174
00175
00176 ACE_INLINE void
00177 ACE_Thread_Descriptor::set_next (ACE_Thread_Descriptor *td)
00178 {
00179 ACE_TRACE ("ACE_Thread_Descriptor::set_next");
00180 this->next_ = td;
00181 }
00182
00183
00184 ACE_INLINE ACE_Thread_Descriptor *
00185 ACE_Thread_Descriptor::get_next (void) const
00186 {
00187 ACE_TRACE ("ACE_Thread_Descriptor::get_next");
00188 return ACE_static_cast (ACE_Thread_Descriptor * ACE_CAST_CONST,
00189 this->next_);
00190 }
00191
00192
00193 ACE_INLINE void
00194 ACE_Thread_Descriptor::reset (ACE_Thread_Manager *tm)
00195 {
00196 ACE_TRACE ("ACE_Thread_Descriptor::reset");
00197 this->ACE_Thread_Descriptor_Base::reset ();
00198 #if defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
00199 this->cleanup_info_.cleanup_hook_ = 0;
00200 this->cleanup_info_.object_ = 0;
00201 this->cleanup_info_.param_ = 0;
00202 #else
00203 this->at_exit_list_ = 0;
00204
00205 this->tm_ = tm;
00206
00207 this->log_msg_ = 0;
00208 this->terminated_ = 0;
00209 #endif
00210 }
00211
00212 ACE_INLINE ACE_Thread_Descriptor *
00213 ACE_Thread_Manager::thread_desc_self (void)
00214 {
00215
00216
00217
00218 ACE_Thread_Descriptor *desc = ACE_LOG_MSG->thr_desc ();
00219
00220 #if 1
00221
00222
00223 #else
00224 if (desc == 0)
00225 {
00226 ACE_thread_t id = ACE_OS::thr_self ();
00227
00228 desc = this->find_thread (id);
00229
00230
00231
00232 if (desc != 0)
00233
00234 ACE_LOG_MSG->thr_desc (desc);
00235 }
00236 #endif
00237 return desc;
00238 }
00239
00240
00241
00242 ACE_INLINE ACE_thread_t
00243 ACE_Thread_Manager::thr_self (void)
00244 {
00245 ACE_TRACE ("ACE_Thread_Manager::thr_self");
00246 return ACE_Thread::self ();
00247 }
00248
00249 ACE_INLINE ACE_Task_Base *
00250 ACE_Thread_Manager::task (void)
00251 {
00252 ACE_TRACE ("ACE_Thread_Manager::task");
00253
00254 ACE_Thread_Descriptor *td = this->thread_desc_self () ;
00255
00256 if (td == 0)
00257 return 0;
00258 else
00259 return td->task ();
00260 }
00261
00262 ACE_INLINE int
00263 ACE_Thread_Manager::open (size_t)
00264 {
00265
00266 return 0;
00267 }
00268
00269 #if !defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT)
00270 ACE_INLINE int
00271 ACE_Thread_Manager::at_exit (ACE_At_Thread_Exit* at)
00272 {
00273 ACE_Thread_Descriptor *td = this->thread_desc_self ();
00274 if (td == 0)
00275 return -1;
00276 else
00277 return td->at_exit (at);
00278 }
00279
00280 ACE_INLINE int
00281 ACE_Thread_Manager::at_exit (ACE_At_Thread_Exit& at)
00282 {
00283 ACE_Thread_Descriptor *td = this->thread_desc_self ();
00284 if (td == 0)
00285 return -1;
00286 else
00287 return td->at_exit (at);
00288 }
00289 #endif
00290
00291 ACE_INLINE int
00292 ACE_Thread_Manager::at_exit (void *object,
00293 ACE_CLEANUP_FUNC cleanup_hook,
00294 void *param)
00295 {
00296 ACE_Thread_Descriptor *td = this->thread_desc_self ();
00297 if (td == 0)
00298 return -1;
00299 else
00300 return td->at_exit (object,
00301 cleanup_hook,
00302 param);
00303 }
00304
00305 ACE_INLINE void
00306 ACE_Thread_Manager::wait_on_exit (int do_wait)
00307 {
00308 this->automatic_wait_ = do_wait;
00309 }
00310
00311 ACE_INLINE int
00312 ACE_Thread_Manager::wait_on_exit (void)
00313 {
00314 return this->automatic_wait_;
00315 }
00316
00317 ACE_INLINE int
00318 ACE_Thread_Manager::register_as_terminated (ACE_Thread_Descriptor *td)
00319 {
00320 #if defined (VXWORKS)
00321 ACE_UNUSED_ARG (td);
00322 #else
00323 ACE_Thread_Descriptor_Base *tdb;
00324 ACE_NEW_RETURN (tdb, ACE_Thread_Descriptor_Base (*td), -1);
00325 this->terminated_thr_list_.insert_tail (tdb);
00326 #endif
00327 return 0;
00328 }
00329
00330 ACE_INLINE size_t
00331 ACE_Thread_Manager::count_threads (void) const
00332 {
00333 return this->thr_list_.size ();
00334 }