00001 ////////////////////////////////////////////////////////////////////////// 00002 // // 00003 // XrdClientThread // 00004 // // 00005 // An user friendly thread wrapper // 00006 // Author: F.Furano (INFN, 2005) // 00007 // // 00008 ////////////////////////////////////////////////////////////////////////// 00009 00010 // $Id: XrdClientThread.hh 22437 2008-03-04 14:35:16Z rdm $ 00011 00012 #ifndef XRC_THREAD_H 00013 #define XRC_THREAD_H 00014 00015 #include "XrdSys/XrdSysPthread.hh" 00016 00017 void * XrdClientThreadDispatcher(void * arg); 00018 00019 class XrdClientThread { 00020 private: 00021 pthread_t fThr; 00022 00023 typedef void *(*VoidRtnFunc_t)(void *, XrdClientThread *); 00024 VoidRtnFunc_t ThreadFunc; 00025 friend void *XrdClientThreadDispatcher(void *); 00026 00027 public: 00028 struct XrdClientThreadArgs { 00029 void *arg; 00030 XrdClientThread *threadobj; 00031 } fArg; 00032 00033 00034 XrdClientThread(VoidRtnFunc_t fn) { 00035 #ifndef WIN32 00036 fThr = 0; 00037 #endif 00038 ThreadFunc = fn; 00039 }; 00040 00041 virtual ~XrdClientThread() { 00042 00043 // Cancel(); 00044 }; 00045 00046 int Cancel() { 00047 return XrdSysThread::Cancel(fThr); 00048 }; 00049 00050 int Run(void *arg = 0) { 00051 fArg.arg = arg; 00052 fArg.threadobj = this; 00053 return XrdSysThread::Run(&fThr, XrdClientThreadDispatcher, (void *)&fArg, 00054 XRDSYSTHREAD_HOLD, ""); 00055 }; 00056 00057 int Detach() { 00058 return XrdSysThread::Detach(fThr); 00059 }; 00060 00061 int Join(void **ret = 0) { 00062 return XrdSysThread::Join(fThr, ret); 00063 }; 00064 00065 // these funcs are to be called only from INSIDE the thread loop 00066 int SetCancelOn() { 00067 return XrdSysThread::SetCancelOn(); 00068 }; 00069 int SetCancelOff() { 00070 return XrdSysThread::SetCancelOff(); 00071 }; 00072 int SetCancelAsynchronous() { 00073 return XrdSysThread::SetCancelAsynchronous(); 00074 }; 00075 int SetCancelDeferred() { 00076 return XrdSysThread::SetCancelDeferred(); 00077 }; 00078 void CancelPoint() { 00079 XrdSysThread::CancelPoint(); 00080 }; 00081 00082 int MaskSignal(int snum = 0, bool block = 1); 00083 }; 00084 00085 00086 00087 #endif