pthread_thread.hpp

00001 #line 126 "./lpsrc/flx_pthread.pak"
00002 #ifndef __FLX_PTHREAD_THREAD_H__
00003 #define __FLX_PTHREAD_THREAD_H__
00004 #include <flx_pthread_config.hpp>
00005 
00006 #if FLX_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 #ifdef _WIN32
00028 typedef HANDLE flx_native_thread_t;
00029 #else
00030 typedef pthread_t flx_native_thread_t;
00031 #endif
00032 
00033 // a class for threads that can't be joined. upon exit all their resources
00034 // are freed. they just evaporate. probably the best type of thread.
00035 class PTHREAD_EXTERN flx_detached_thread_t {
00036   flx_native_thread_t thr;        ///< the thread
00037   flx_detached_thread_t(flx_detached_thread_t const&); // uncopyable
00038   void operator=(flx_detached_thread_t const&); // uncopyable
00039 public:
00040   flx_detached_thread_t();
00041   ~flx_detached_thread_t();
00042   int init(void (*start)(void*), void* udat);
00043 };
00044 
00045 // rf: joinable threads. is it an error to not join joinable threads?
00046 class PTHREAD_EXTERN flx_thread_t {
00047   flx_native_thread_t thr;        ///< the thread
00048   flx_thread_t(flx_thread_t const&); // uncopyable
00049   void operator=(flx_thread_t const&); // uncopyable
00050 public:
00051   flx_thread_t();
00052   ~flx_thread_t();
00053   int init(void (*start)(void*), void* udat);
00054   void join();
00055 };
00056 
00057 /// RAII wrapper for thread class
00058 class PTHREAD_EXTERN flx_thread_wrapper_t {
00059   flx_thread_t thread;
00060   flx_thread_wrapper_t(flx_thread_wrapper_t const&); // uncopyable
00061   void operator=(flx_thread_wrapper_t const&); // uncopyable
00062 public:
00063   ~flx_thread_wrapper_t();
00064   flx_thread_wrapper_t(void (*start)(void*), void* udat);
00065 };
00066 
00067 }}
00068 #endif
00069 

Generated on Mon Dec 24 07:59:57 2007 for Felix by  doxygen 1.5.4