pthread_thread.hpp

00001 #line 233 "./lpsrc/flx_pthread.pak"
00002 #ifndef __FLX_THREAD__
00003 #define __FLX_THREAD__
00004 #include <flx_pthread_config.hpp>
00005 
00006 #ifdef _WIN32
00007 #include <windows.h>
00008 #else
00009 #include <pthread.h>
00010 #endif
00011 
00012 // auto pthread, because I forget how to deallocate them nicely
00013 // could init in the constructor, but ultimately you don't want the thread
00014 // barging in before you've finished doing other stuff
00015 // Addendum (20051128): doing stdio in turns out to be not very safe.
00016 // I don't know if printf et al are supposed to be thread safe (most impls
00017 // seem to try to be) but I sometimes get deadlocks in ppc64 os x 10.4.2
00018 // with 4.0.1 when printfing to stdout. Nasty.
00019 
00020 namespace flx { namespace pthread {
00021 
00022 // ********************************************************
00023 /// Posix Threads. This class simply wraps the creation
00024 /// and joining of threads. It is not safe.
00025 // ********************************************************
00026 
00027 class PTHREAD_EXTERN flx_detached_thread_t {
00028 #ifdef _WIN32
00029   HANDLE    thread;
00030 #else
00031   pthread_t   thr;        ///< the thread
00032 #endif
00033   flx_detached_thread_t(flx_detached_thread_t const&); // uncopyable
00034   void operator=(flx_detached_thread_t const&); // uncopyable
00035 public:
00036   flx_detached_thread_t();
00037   ~flx_detached_thread_t();
00038 #ifdef _WIN32
00039   int init(LPTHREAD_START_ROUTINE, LPVOID lParam);
00040 #else
00041   int init(void* (*start)(void*), void* udat);
00042 #endif
00043 };
00044 
00045 class PTHREAD_EXTERN flx_thread_t {
00046 #ifdef _WIN32
00047   HANDLE    thread;
00048 #else
00049   pthread_t   thr;        ///< the thread
00050 #endif
00051   flx_thread_t(flx_thread_t const&); // uncopyable
00052   void operator=(flx_thread_t const&); // uncopyable
00053 public:
00054   flx_thread_t();
00055   ~flx_thread_t();
00056 #ifdef _WIN32
00057   int init(LPTHREAD_START_ROUTINE, LPVOID lParam);
00058 #else
00059   int init(void* (*start)(void*), void* udat);
00060 #endif
00061   void join();
00062 };
00063 
00064 /// RAII wrapper for thread class
00065 class PTHREAD_EXTERN flx_thread_wrapper_t {
00066   flx_thread_t thread;
00067   flx_thread_wrapper_t(flx_thread_wrapper_t const&); // uncopyable
00068   void operator=(flx_thread_wrapper_t const&); // uncopyable
00069 public:
00070   ~flx_thread_wrapper_t();
00071 #ifndef _WIN32
00072   flx_thread_wrapper_t(void* (*start)(void*), void* udat);
00073 #else
00074   flx_thread_wrapper_t(LPTHREAD_START_ROUTINE, LPVOID);
00075 #endif
00076 };
00077 
00078 }}
00079 #endif
00080 

Generated on Mon Dec 11 17:08:15 2006 for Felix by  doxygen 1.5.1