(file) Return to Thread.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/Thread.cpp between version 1.94 and 1.100.2.6

version 1.94, 2006/08/21 15:31:03 version 1.100.2.6, 2008/10/23 18:59:32
Line 32 
Line 32 
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include "Thread.h" #include "Thread.h"
   #include <errno.h>
 #include <exception> #include <exception>
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include "Time.h" #include "Time.h"
Line 56 
Line 57 
  
 extern "C" void *_start_wrapper(void *arg_) extern "C" void *_start_wrapper(void *arg_)
 { {
     StartWrapperArg *arg = (StartWrapperArg *) arg_;      // Clean up dynamic memory now to prevent a leak if the thread is canceled.
       StartWrapperArg arg;
       arg.start = ((StartWrapperArg *) arg_)->start;
       arg.arg = ((StartWrapperArg *) arg_)->arg;
       delete (StartWrapperArg *) arg_;
  
     void *return_value = (*arg->start) (arg->arg);      // establish cancelability of the thread
     delete arg;      pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
       pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
   
       void *return_value = (*arg.start) (arg.arg);
  
     return return_value;     return return_value;
 } }
Line 79 
Line 87 
 #endif #endif
 } }
  
 Boolean Thread::is_cancelled(void)  Boolean Thread::is_cancelled()
 { {
     return _cancelled;     return _cancelled;
 } }
Line 113 
Line 121 
     Threads::sleep(msec);     Threads::sleep(msec);
 } }
  
 void Thread::join(void)  void Thread::join()
 { {
     if (!_is_detached && !Threads::null(_handle.thid))     if (!_is_detached && !Threads::null(_handle.thid))
         pthread_join(_handle.thid.thread, &_exit_code);         pthread_join(_handle.thid.thread, &_exit_code);
Line 121 
Line 129 
     Threads::clear(_handle.thid);     Threads::clear(_handle.thid);
 } }
  
 void Thread::thread_init(void)  void Thread::thread_init()
 { {
 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
     pthread_setintr(PTHREAD_INTR_ENABLE);     pthread_setintr(PTHREAD_INTR_ENABLE);
Line 133 
Line 141 
     _cancel_enabled = true;     _cancel_enabled = true;
 } }
  
 void Thread::detach(void)  void Thread::detach()
 { {
     _is_detached = true;     _is_detached = true;
 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
Line 150 
Line 158 
     arg->start = _start;     arg->start = _start;
     arg->arg = this;     arg->arg = this;
  
     Threads::Type type = _is_detached ? Threads::DETACHED : Threads::JOINABLE;      Threads::Type type =
           _is_detached ? Threads::THREADS_DETACHED : Threads::THREADS_JOINABLE;
     int rc = Threads::create(_handle.thid, type, _start_wrapper, arg);     int rc = Threads::create(_handle.thid, type, _start_wrapper, arg);
  
     // On Linux distributions released prior 2005, the implementation of     // On Linux distributions released prior 2005, the implementation of
Line 207 
Line 216 
     return sig;     return sig;
 } }
  
 Thread::Thread(ThreadReturnType(PEGASUS_THREAD_CDECL * start) (void *), void *parameter, Boolean detached):_is_detached(detached),  /*
   ATTN: remove this!
   */
   #if 1
   static Uint32 _num_threads = 0;
   static Mutex _num_threads_mutex;
   #endif
   
   Thread::Thread(
       ThreadReturnType(PEGASUS_THREAD_CDECL* start) (void*),
       void* parameter,
       Boolean detached)
       : _is_detached(detached),
 _cancel_enabled(true), _cancel_enabled(true),
 _cancelled(false), _cancelled(false),
 _start(start), _cleanup(), _tsd(), _thread_parm(parameter), _exit_code(0)        _start(start),
         _cleanup(),
         _tsd(),
         _thread_parm(parameter),
         _exit_code(0)
 { {
   /*
   ATTN: remove this!
   */
   #if 1
       Uint32 num_threads;
       _num_threads_mutex.lock();
       _num_threads++;
       num_threads = _num_threads;
       printf("Thread::Thread(): num_threads=%u\n", num_threads);
       _num_threads_mutex.unlock();
   #endif
   
     Threads::clear(_handle.thid);     Threads::clear(_handle.thid);
 } }
  
 Thread::~Thread() Thread::~Thread()
 { {
   /*
   ATTN: remove this!
   */
   #if 1
       Uint32 num_threads;
       _num_threads_mutex.lock();
       _num_threads--;
       num_threads = _num_threads;
       printf("Thread::~Thread(): num_threads=%u\n", num_threads);
       _num_threads_mutex.unlock();
   #endif
   
     try     try
     {     {
         join();         join();
Line 238 
Line 287 
  
 #if defined(PEGASUS_HAVE_WINDOWS_THREADS) #if defined(PEGASUS_HAVE_WINDOWS_THREADS)
  
 ThreadStatus Thread::run(void)  ThreadStatus Thread::run()
 { {
     // Note: A Win32 thread ID is not the same thing as a pthread ID.     // Note: A Win32 thread ID is not the same thing as a pthread ID.
     // Win32 threads have both a thread ID and a handle.  The handle     // Win32 threads have both a thread ID and a handle.  The handle
Line 251 
Line 300 
     tt.handle = (HANDLE) _beginthreadex(NULL, 0, _start, this, 0, &threadid);     tt.handle = (HANDLE) _beginthreadex(NULL, 0, _start, this, 0, &threadid);
     _handle.thid = tt;     _handle.thid = tt;
  
     if (Threads::id(_handle.thid) == 0)      if (Threads::null(_handle.thid))
     {     {
         if (errno == EAGAIN)         if (errno == EAGAIN)
         {         {
Line 265 
Line 314 
     return PEGASUS_THREAD_OK;     return PEGASUS_THREAD_OK;
 } }
  
 void Thread::cancel(void)  void Thread::cancel()
 { {
     _cancelled = true;     _cancelled = true;
 } }
  
 void Thread::test_cancel(void)  void Thread::test_cancel()
 { {
     if (_cancel_enabled && _cancelled)     if (_cancel_enabled && _cancelled)
     {     {
Line 278 
Line 327 
     }     }
 } }
  
 Boolean Thread::is_cancelled(void)  Boolean Thread::is_cancelled()
 { {
     return _cancelled;     return _cancelled;
 } }
  
 void Thread::thread_switch(void)  void Thread::thread_switch()
 { {
     Sleep(0);     Sleep(0);
 } }
Line 293 
Line 342 
     Sleep(milliseconds);     Sleep(milliseconds);
 } }
  
 void Thread::join(void)  void Thread::join()
 { {
     if (Threads::id(_handle.thid) != 0)      if (!Threads::null(_handle.thid))
     {     {
         if (!_is_detached)         if (!_is_detached)
         {         {
Line 327 
Line 376 
     }     }
 } }
  
 void Thread::thread_init(void)  void Thread::thread_init()
 { {
     _cancel_enabled = true;     _cancel_enabled = true;
 } }
  
 void Thread::detach(void)  void Thread::detach()
 { {
     _is_detached = true;     _is_detached = true;
 } }
Line 415 
Line 464 
 } }
  
  
 //thread_data *Thread::put_tsd(const Sint8 *key, void (*delete_func)(void *), Uint32 size, void *value)  
   
   
 void Thread::exit_self(ThreadReturnType exit_code) void Thread::exit_self(ThreadReturnType exit_code)
 { {
 #if defined(PEGASUS_PLATFORM_HPUX_ACC) || \  #if !defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) \
     defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)      && !defined(PEGASUS_PLATFORM_PASE_ISERIES_IBMCXX)
     // NOTE: pthread_exit exhibits unusual behavior on RHEL 3 U2, as      Threads::exit(exit_code);
     // documented in Bugzilla 3836.  Where feasible, it may be advantageous  
     // to avoid using this function.  
     pthread_exit(exit_code);  
 #else #else
     // execute the cleanup stack and then return     // execute the cleanup stack and then return
     while (_cleanup.size())     while (_cleanup.size())
Line 453 
Line 496 
     {     {
         if (Thread::_key_error)         if (Thread::_key_error)
         {         {
             Tracer::trace(TRC_THREAD, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL4,
                           "Thread: ERROR - thread key error");                           "Thread: ERROR - thread key error");
             return -1;             return -1;
         }         }
  
         if (TSDKey::create(&Thread::_platform_thread_key) == 0)         if (TSDKey::create(&Thread::_platform_thread_key) == 0)
         {         {
             Tracer::trace(TRC_THREAD, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL4,
                           "Thread: able to create a thread key");                           "Thread: able to create a thread key");
             Thread::_key_initialized = true;             Thread::_key_initialized = true;
         }         }
         else         else
         {         {
             Tracer::trace(TRC_THREAD, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL4,
                           "Thread: ERROR - unable to create a thread key");                           "Thread: ERROR - unable to create a thread key");
             Thread::_key_error = true;             Thread::_key_error = true;
             return -1;             return -1;
Line 497 
Line 540 
             set_thread_specific(Thread::_platform_thread_key,             set_thread_specific(Thread::_platform_thread_key,
                                 (void *) thrd) == 0)                                 (void *) thrd) == 0)
         {         {
             Tracer::trace(TRC_THREAD, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL4,
                 "Successful set Thread * into thread specific storage");                 "Successful set Thread * into thread specific storage");
         }         }
         else         else
         {         {
             Tracer::trace(TRC_THREAD, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_THREAD, Tracer::LEVEL4,
                 "ERROR: error setting Thread * into thread specific storage");                 "ERROR: error setting Thread * into thread specific storage");
         }         }
     }     }
Line 523 
Line 566 
     return acceptLangs;     return acceptLangs;
 } }
  
 void Thread::setLanguages(AcceptLanguageList * langs)   // l10n  void Thread::setLanguages(AcceptLanguageList * langs)
 { {
     PEG_METHOD_ENTER(TRC_THREAD, "Thread::setLanguages");     PEG_METHOD_ENTER(TRC_THREAD, "Thread::setLanguages");
  
Line 539 
Line 582 
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
 } }
  
 void Thread::clearLanguages()   // l10n  void Thread::clearLanguages()
 { {
     PEG_METHOD_ENTER(TRC_THREAD, "Thread::clearLanguages");     PEG_METHOD_ENTER(TRC_THREAD, "Thread::clearLanguages");
  


Legend:
Removed from v.1.94  
changed lines
  Added in v.1.100.2.6

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2