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

Diff for /pegasus/src/Pegasus/Common/Threads.cpp between version 1.1.2.1 and 1.1.2.3

version 1.1.2.1, 2006/07/27 23:11:52 version 1.1.2.3, 2006/07/28 17:58:21
Line 34 
Line 34 
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include "Threads.h" #include "Threads.h"
   #include "IDFactory.h"
   #include "TSDKey.h"
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
Line 110 
Line 112 
 #endif #endif
 } }
  
   //==============================================================================
   //
   // Thread id TSD:
   //
   //==============================================================================
   
   static MutexType _mutex = PEGASUS_MUTEX_INITIALIZER;
   static int _initialized;
   static TSDKeyType _key;
   
   static void _init_id_tsd()
   {
       mutex_lock(&_mutex);
   
       if (_initialized == 0)
       {
           TSDKey::create(&_key);
           _initialized = 1;
       }
   
       mutex_unlock(&_mutex);
   }
   
   static inline void _set_id_tsd(Uint32 id)
   {
       if (_initialized == 0)
           _init_id_tsd();
   
       TSDKey::set_thread_specific(_key, (void*)(long)id);
   }
   
   static inline Uint32 _get_id_tsd()
   {
       if (_initialized == 0)
           _init_id_tsd();
   
       void* ptr = TSDKey::get_thread_specific(_key);
   
       if (!ptr)
       {
           // Main thread's id is 1!
           return 1;
       }
   
       return (Uint32)(long)ptr;
   }
   
   //==============================================================================
   //
   // PEGASUS_HAVE_PTHREADS
   //
   //==============================================================================
   
   static IDFactory _thread_ids(2); /* 1 reserved for main thread */
   
   #if defined(PEGASUS_HAVE_PTHREADS)
   
   int Threads::create(
       ThreadType& thread,
       Type type,
       void* (*start)(void*),
       void* arg)
   {
       // Initialize thread attributes:
   
       pthread_attr_t attr;
       pthread_attr_init(&attr);
   
       if (type == DETACHED)
       {
   #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
           int ds = 1;
           pthread_attr_setdetachstate(&_handle.thatt, &ds);
   #else
           pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
   #endif
       }
   
   #if defined(PEGASUS_PLATFORM_SOLARIS_SPARC_GNU) || \
       defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
   # if defined SUNOS_5_7
       pthread_attr_setschedpolicy(&attr, SCHED_RR);
   # else
       pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
   # endif
   #endif // PEGASUS_PLATFORM_SOLARIS_SPARC_GNU
   
       // Create thread:
   
       pthread_t thr;
       int rc = pthread_create(&thr, &attr, start, arg);
   
       if (rc != 0)
       {
           thread = ThreadType();
           return rc;
       }
   
       // Assign thread id (and put into thread specific storage).
   
       Uint32 id = _thread_ids.getID();
       _set_id_tsd(id);
   
       // Return:
   
       thread = ThreadType(thr, id);
       return 0;
   }
   
   ThreadType Threads::self()
   {
       return ThreadType(pthread_self(), _get_id_tsd());
   }
   
   #endif /* PEGASUS_HAVE_PTHREADS */
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.1.2.3

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2