Thread.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Thread.inl,v 4.4 2005/10/28 23:55:10 ossama Exp
00004 
00005 #include "ace/OS_NS_string.h"
00006 
00007 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00008 
00009 // Allocates a <keyp> that is used to identify data that is specific
00010 // to each thread in the process.  The key is global to all threads in
00011 // the process.
00012 
00013 ACE_INLINE int
00014 ACE_Thread::keycreate (ACE_thread_key_t *keyp,
00015 #if defined (ACE_HAS_THR_C_DEST)
00016                        ACE_THR_C_DEST destructor,
00017 #else
00018                        ACE_THR_DEST destructor,
00019 #endif /* ACE_HAS_THR_C_DEST */
00020                        void *inst)
00021 {
00022   // ACE_TRACE ("ACE_Thread::keycreate");
00023   return ACE_OS::thr_keycreate (keyp, destructor, inst);
00024 }
00025 
00026 // Free up the key so that other threads can reuse it.
00027 
00028 ACE_INLINE int
00029 ACE_Thread::keyfree (ACE_thread_key_t key)
00030 {
00031   ACE_TRACE ("ACE_Thread::keyfree");
00032   return ACE_OS::thr_keyfree (key);
00033 }
00034 
00035 // Bind value to the thread-specific data key, <key>, for the calling
00036 // thread.
00037 
00038 ACE_INLINE int
00039 ACE_Thread::setspecific (ACE_thread_key_t key, void *value)
00040 {
00041   // ACE_TRACE ("ACE_Thread::setspecific");
00042   return ACE_OS::thr_setspecific (key, value);
00043 }
00044 
00045 // Stores the current value bound to <key> for the calling thread
00046 // into the location pointed to by <valuep>.
00047 
00048 ACE_INLINE int
00049 ACE_Thread::getspecific (ACE_thread_key_t key, void **valuep)
00050 {
00051   // ACE_TRACE ("ACE_Thread::getspecific");
00052   return ACE_OS::thr_getspecific (key, valuep);
00053 }
00054 
00055 ACE_INLINE ACE_thread_t
00056 ACE_Thread::self (void)
00057 {
00058 //  ACE_TRACE ("ACE_Thread::self");
00059   return ACE_OS::thr_self ();
00060 }
00061 
00062 ACE_INLINE void
00063 ACE_Thread::exit (ACE_THR_FUNC_RETURN status)
00064 {
00065   ACE_TRACE ("ACE_Thread::exit");
00066   ACE_OS::thr_exit (status);
00067 }
00068 
00069 ACE_INLINE void
00070 ACE_Thread::yield (void)
00071 {
00072   ACE_TRACE ("ACE_Thread::yield");
00073   ACE_OS::thr_yield ();
00074 }
00075 
00076 ACE_INLINE int
00077 ACE_Thread::spawn (ACE_THR_FUNC func,
00078                    void *arg,
00079                    long flags,
00080                    ACE_thread_t *t_id,
00081                    ACE_hthread_t *t_handle,
00082                    long priority,
00083                    void *thr_stack,
00084                    size_t thr_stack_size,
00085                    ACE_Thread_Adapter *thread_adapter)
00086 {
00087   ACE_TRACE ("ACE_Thread::spawn");
00088 
00089   return ACE_OS::thr_create (func,
00090                              arg,
00091                              flags,
00092                              t_id,
00093                              t_handle,
00094                              priority,
00095                              thr_stack,
00096                              thr_stack_size,
00097                              thread_adapter);
00098 }
00099 
00100 ACE_INLINE int
00101 ACE_Thread::resume (ACE_hthread_t t_id)
00102 {
00103   ACE_TRACE ("ACE_Thread::resume");
00104   return ACE_OS::thr_continue (t_id);
00105 }
00106 
00107 ACE_INLINE int
00108 ACE_Thread::suspend (ACE_hthread_t t_id)
00109 {
00110   ACE_TRACE ("ACE_Thread::suspend");
00111   return ACE_OS::thr_suspend (t_id);
00112 }
00113 
00114 ACE_INLINE int
00115 ACE_Thread::kill (ACE_thread_t t_id, int signum)
00116 {
00117   ACE_TRACE ("ACE_Thread::kill");
00118   return ACE_OS::thr_kill (t_id, signum);
00119 }
00120 
00121 ACE_INLINE int
00122 ACE_Thread::join (ACE_thread_t wait_for,
00123                   ACE_thread_t *departed,
00124                   ACE_THR_FUNC_RETURN *status)
00125 {
00126   ACE_TRACE ("ACE_Thread::join");
00127   return ACE_OS::thr_join (wait_for, departed, status);
00128 }
00129 
00130 ACE_INLINE int
00131 ACE_Thread::join (ACE_hthread_t wait_for,
00132                   ACE_THR_FUNC_RETURN *status)
00133 {
00134   ACE_TRACE ("ACE_Thread::join");
00135   return ACE_OS::thr_join (wait_for, status);
00136 }
00137 
00138 ACE_INLINE int
00139 ACE_Thread::getconcurrency (void)
00140 {
00141   ACE_TRACE ("ACE_Thread::getconcurrency");
00142   return ACE_OS::thr_getconcurrency ();
00143 }
00144 
00145 ACE_INLINE int
00146 ACE_Thread::setconcurrency (int new_level)
00147 {
00148   ACE_TRACE ("ACE_Thread::setconcurrency");
00149   return ACE_OS::thr_setconcurrency (new_level);
00150 }
00151 
00152 ACE_INLINE int
00153 ACE_Thread::sigsetmask (int how,
00154                         const sigset_t *sigset,
00155                         sigset_t *osigset)
00156 {
00157   ACE_TRACE ("ACE_Thread::sigsetmask");
00158   return ACE_OS::thr_sigsetmask (how, sigset, osigset);
00159 }
00160 
00161 ACE_INLINE int
00162 ACE_Thread::disablecancel (struct cancel_state *old_state)
00163 {
00164   ACE_TRACE ("ACE_Thread::disablecancel");
00165   int old_cstate = 0;
00166   int result = ACE_OS::thr_setcancelstate (THR_CANCEL_DISABLE,
00167                                            &old_cstate);
00168   if (result == 0 && old_state != 0)
00169     {
00170       ACE_OS::memset (old_state,
00171                       0,
00172                       sizeof (old_state));
00173       old_state->cancelstate = old_cstate;
00174     }
00175 
00176   return result;
00177 }
00178 
00179 ACE_INLINE int
00180 ACE_Thread::enablecancel (struct cancel_state *old_state,
00181                           int flag)
00182 {
00183   ACE_TRACE ("ACE_Thread::enablecancel");
00184   int old_cstate = 0;
00185   int old_ctype = 0;
00186   int result;
00187 
00188   result = ACE_OS::thr_setcancelstate (THR_CANCEL_ENABLE,
00189                                        &old_cstate);
00190   if (result != 0)
00191     return result;
00192 
00193   result = ACE_OS::thr_setcanceltype (flag,
00194                                       &old_ctype);
00195   if (result != 0)
00196     return result;
00197 
00198   if (old_state != 0)
00199     {
00200       old_state->cancelstate = old_cstate;
00201       old_state->canceltype = old_ctype;
00202     }
00203 
00204   return 0;
00205 }
00206 
00207 ACE_INLINE int
00208 ACE_Thread::setcancelstate (struct cancel_state &new_state,
00209                             struct cancel_state *old_state)
00210 {
00211   ACE_TRACE ("ACE_Thread::setcancelstate");
00212   int old_cstate = 0;
00213   int old_ctype = 0;
00214 
00215   if (new_state.cancelstate != 0
00216       && ACE_OS::thr_setcancelstate (new_state.cancelstate,
00217                                      &old_cstate) != 0)
00218     return -1;
00219 
00220   if (new_state.canceltype != 0
00221       && ACE_OS::thr_setcanceltype (new_state.canceltype,
00222                                     &old_ctype) != 0)
00223     {
00224       int o_cstate;
00225 
00226       ACE_OS::thr_setcancelstate (old_cstate,
00227                                   &o_cstate);
00228       return -1;
00229     }
00230 
00231   if (old_state != 0)
00232     {
00233       old_state->cancelstate = old_cstate;
00234       old_state->canceltype = old_ctype;
00235     }
00236 
00237   return 0;
00238 }
00239 
00240 ACE_INLINE int
00241 ACE_Thread::cancel (ACE_thread_t t_id)
00242 {
00243   ACE_TRACE ("ACE_Thread::cancel");
00244 
00245   return ACE_OS::thr_cancel (t_id);
00246 }
00247 
00248 ACE_INLINE void
00249 ACE_Thread::testcancel (void)
00250 {
00251   ACE_TRACE ("ACE_Thread::testcancel");
00252 
00253   ACE_OS::thr_testcancel ();
00254 }
00255 
00256 ACE_INLINE void
00257 ACE_Thread::self (ACE_hthread_t &t_id)
00258 {
00259 //  ACE_TRACE ("ACE_Thread::self");
00260   ACE_OS::thr_self (t_id);
00261 }
00262 
00263 ACE_INLINE int
00264 ACE_Thread::getprio (ACE_hthread_t ht_id, int &priority)
00265 {
00266   ACE_TRACE ("ACE_Thread::getprio");
00267   return ACE_OS::thr_getprio (ht_id, priority);
00268 }
00269 
00270 ACE_INLINE int
00271 ACE_Thread::getprio (ACE_hthread_t ht_id, int &priority, int &policy)
00272 {
00273   ACE_TRACE ("ACE_Thread::getprio");
00274   return ACE_OS::thr_getprio (ht_id, priority, policy);
00275 }
00276 
00277 ACE_INLINE int
00278 ACE_Thread::setprio (ACE_hthread_t ht_id, int priority, int policy)
00279 {
00280   ACE_TRACE ("ACE_Thread::setprio");
00281   return ACE_OS::thr_setprio (ht_id, priority, policy);
00282 }
00283 
00284 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6