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

Diff for /pegasus/src/Pegasus/Common/Threads.h between version 1.1.2.2 and 1.1.2.9

version 1.1.2.2, 2006/07/28 17:41:27 version 1.1.2.9, 2006/07/28 21:51:00
Line 40 
Line 40 
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/Linkage.h> #include <Pegasus/Common/Linkage.h>
  
   // ATTN: can we consolidate these someplace?
   
 #if defined(PEGASUS_HAVE_PTHREADS) #if defined(PEGASUS_HAVE_PTHREADS)
 # if defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) # if defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
 # define _MULTI_THREADED // Is this really necessary? # define _MULTI_THREADED // Is this really necessary?
Line 49 
Line 51 
 # include <sys/time.h> # include <sys/time.h>
 #elif defined(PEGASUS_HAVE_WINDOWS_THREADS) #elif defined(PEGASUS_HAVE_WINDOWS_THREADS)
 # include <windows.h> # include <windows.h>
   # include <process.h>
 #else #else
 # error "<Pegasus/Common/Threads.h>: not implemented" # error "<Pegasus/Common/Threads.h>: not implemented"
 #endif #endif
Line 69 
Line 72 
  
 //============================================================================== //==============================================================================
 // //
 // Thread-related type definitions  // ThreadType
 // //
 //============================================================================== //==============================================================================
  
 #if defined(PEGASUS_HAVE_PTHREADS) #if defined(PEGASUS_HAVE_PTHREADS)
   
 struct ThreadType struct ThreadType
 { {
 public: public:
  
     ThreadType()     ThreadType()
     {     {
         clear();          memset(this, 0, sizeof(*this));
     }     }
  
     ThreadType(const ThreadType& x) : _thread(x._thread), _id(x._id)     ThreadType(const ThreadType& x) : _thread(x._thread), _id(x._id)
Line 102 
Line 104 
         return *this;         return *this;
     }     }
  
     void clear()      pthread_t tt_handle() const
     {  
         memset(this, 0, sizeof(*this));  
     }  
   
     pthread_t thread() const  
     {     {
         return _thread;         return _thread;
     }     }
  
     Uint32 id() const  
     {  
         return _id;  
     }  
   
     void print() const     void print() const
     {     {
         printf("ThreadType(%lu, %lu)\n", _thread, (unsigned long)_id);         printf("ThreadType(%lu, %lu)\n", _thread, (unsigned long)_id);
Line 124 
Line 116 
  
 private: private:
     pthread_t _thread;     pthread_t _thread;
       // An id of zero indicates a null object. 1 indicates the main thread.
     // And id of zero indicates a null object. 1 indicates the main thread.  
     Uint32 _id;     Uint32 _id;
       friend class Threads;
 }; };
   #endif /* PEGASUS_HAVE_PTHREADS */
   
   #if defined(PEGASUS_HAVE_WINDOWS_THREADS)
   struct ThreadType
   {
       ThreadType() : handle(NULL) { }
       HANDLE handle;
   };
   #endif /* PEGASUS_HAVE_WINDOWS_THREADS */
   
   //==============================================================================
   //
   // ThreadReturnType
   //
   //==============================================================================
  
   #if defined(PEGASUS_HAVE_PTHREADS)
 typedef void* ThreadReturnType; typedef void* ThreadReturnType;
 #endif #endif
  
 #if defined(PEGASUS_HAVE_WINDOWS_THREADS) #if defined(PEGASUS_HAVE_WINDOWS_THREADS)
 typedef HANDLE ThreadType;  
 typedef unsigned ThreadReturnType; typedef unsigned ThreadReturnType;
 #endif #endif
  
Line 147 
Line 154 
 struct ThreadHandle struct ThreadHandle
 { {
     ThreadType thid;     ThreadType thid;
     pthread_attr_t thatt;  
 }; };
 #elif defined(PEGASUS_HAVE_WINDOWS_THREADS) #elif defined(PEGASUS_HAVE_WINDOWS_THREADS)
 struct ThreadHandle struct ThreadHandle
 { {
     ThreadType thid;     ThreadType thid;
     void * thatt;  
 }; };
 #endif #endif
  
Line 190 
Line 195 
     static void cleanup_push(void (*start)(void*), void* arg);     static void cleanup_push(void (*start)(void*), void* arg);
  
     static void cleanup_pop(int execute);     static void cleanup_pop(int execute);
   
       static Uint32 id(const ThreadType& x = Threads::self());
   
       static void clear(ThreadType& x);
 }; };
  
 //============================================================================== //==============================================================================
Line 202 
Line 211 
  
 inline bool Threads::equal(ThreadType x, ThreadType y) inline bool Threads::equal(ThreadType x, ThreadType y)
 { {
     return pthread_equal(x.thread(), y.thread());      return pthread_equal(x.tt_handle(), y.tt_handle());
 } }
  
 inline void Threads::exit(ThreadReturnType rc) inline void Threads::exit(ThreadReturnType rc)
Line 212 
Line 221 
  
 inline void Threads::cancel(ThreadType th, ThreadReturnType rc) inline void Threads::cancel(ThreadType th, ThreadReturnType rc)
 { {
     pthread_cancel(th.thread());      pthread_cancel(th.tt_handle());
 } }
  
 inline void Threads::yield() inline void Threads::yield()
Line 243 
Line 252 
     // ATTN: not implemented.     // ATTN: not implemented.
 } }
  
   inline Uint32 Threads::id(const ThreadType& x)
   {
       return x._id;
   }
   
   inline void Threads::clear(ThreadType& x)
   {
       memset(&x, 0, sizeof(x));
   }
   
 #endif /* defined(PEGASUS_HAVE_PTHREADS) */ #endif /* defined(PEGASUS_HAVE_PTHREADS) */
  
 //============================================================================== //==============================================================================
Line 255 
Line 274 
  
 inline ThreadType Threads::self() inline ThreadType Threads::self()
 { {
     return ThreadType(GetCurrentThreadId());      ThreadType tt;
       tt.handle = HANDLE(GetCurrentThreadId());
       return tt;
 } }
  
 inline bool Threads::equal(ThreadType x, ThreadType y) inline bool Threads::equal(ThreadType x, ThreadType y)
 { {
     return x == y;      return x.handle == y.handle;
 } }
  
 inline void Threads::exit(ThreadReturnType rc) inline void Threads::exit(ThreadReturnType rc)
Line 270 
Line 291 
  
 inline void Threads::cancel(ThreadType th, ThreadReturnType rc) inline void Threads::cancel(ThreadType th, ThreadReturnType rc)
 { {
     TerminateThread(th, rc);      TerminateThread(th.handle, rc);
 } }
  
 inline void Threads::yield() inline void Threads::yield()
Line 288 
Line 309 
     // ATTN: Not implemented on Windows.     // ATTN: Not implemented on Windows.
 } }
  
   inline Uint32 Threads::id(const ThreadType& x)
   {
       return (Uint32)(long)x.handle;
   }
   
   inline void Threads::clear(ThreadType& x)
   {
       x.handle = NULL;
   }
   
 #endif /* defined(PEGASUS_HAVE_WINDOWS_THREADS) */ #endif /* defined(PEGASUS_HAVE_WINDOWS_THREADS) */
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.9

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2