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