xrootd
XrdClientThread.hh
Go to the documentation of this file.
1 #ifndef XRC_THREAD_H
2 #define XRC_THREAD_H
3 /******************************************************************************/
4 /* */
5 /* X r d C l i e n t T h r e a d . h h */
6 /* */
7 /* Author: F.Furano (INFN, 2005) */
8 /* */
9 /* This file is part of the XRootD software suite. */
10 /* */
11 /* XRootD is free software: you can redistribute it and/or modify it under */
12 /* the terms of the GNU Lesser General Public License as published by the */
13 /* Free Software Foundation, either version 3 of the License, or (at your */
14 /* option) any later version. */
15 /* */
16 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19 /* License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24 /* */
25 /* The copyright holder's institutional names and contributor's names may not */
26 /* be used to endorse or promote products derived from this software without */
27 /* specific prior written permission of the institution or contributor. */
28 /******************************************************************************/
29 
31 // //
32 // An user friendly thread wrapper //
33 // //
35 
36 #include "XrdSys/XrdSysPthread.hh"
37 
38 void * XrdClientThreadDispatcher(void * arg);
39 
41 private:
42  pthread_t fThr;
43 
44  typedef void *(*VoidRtnFunc_t)(void *, XrdClientThread *);
46  friend void *XrdClientThreadDispatcher(void *);
47 
48  public:
50  void *arg;
52  } fArg;
53 
54 
56 #ifndef WIN32
57  fThr = 0;
58 #endif
59  ThreadFunc = fn;
60  };
61 
62  virtual ~XrdClientThread() {
63 
64 // Cancel();
65  };
66 
67  int Cancel() {
68  return XrdSysThread::Cancel(fThr);
69  };
70 
71  int Run(void *arg = 0) {
72  fArg.arg = arg;
73  fArg.threadobj = this;
75  XRDSYSTHREAD_HOLD, "");
76  };
77 
78  int Detach() {
79  return XrdSysThread::Detach(fThr);
80  };
81 
82  int Join(void **ret = 0) {
83  return XrdSysThread::Join(fThr, ret);
84  };
85 
86  // these funcs are to be called only from INSIDE the thread loop
87  int SetCancelOn() {
89  };
90  int SetCancelOff() {
92  };
95  };
98  };
99  void CancelPoint() {
101  };
102 
103  int MaskSignal(int snum = 0, bool block = 1);
104 };
105 #endif
int SetCancelOn()
Definition: XrdClientThread.hh:87
int Join(void **ret=0)
Definition: XrdClientThread.hh:82
pthread_t fThr
Definition: XrdClientThread.hh:42
struct XrdClientThread::XrdClientThreadArgs fArg
Definition: XrdClientThread.hh:40
#define XRDSYSTHREAD_HOLD
Definition: XrdSysPthread.hh:458
int Detach()
Definition: XrdClientThread.hh:78
static int Detach(pthread_t tid)
Definition: XrdSysPthread.hh:466
virtual ~XrdClientThread()
Definition: XrdClientThread.hh:62
XrdClientThread * threadobj
Definition: XrdClientThread.hh:51
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
Definition: XrdClientThread.hh:49
VoidRtnFunc_t ThreadFunc
Definition: XrdClientThread.hh:45
void *(* VoidRtnFunc_t)(void *, XrdClientThread *)
Definition: XrdClientThread.hh:44
int Cancel()
Definition: XrdClientThread.hh:67
static int Cancel(pthread_t tid)
Definition: XrdSysPthread.hh:464
int SetCancelOff()
Definition: XrdClientThread.hh:90
int Run(void *arg=0)
Definition: XrdClientThread.hh:71
friend void * XrdClientThreadDispatcher(void *)
static void CancelPoint()
Definition: XrdSysPthread.hh:489
int MaskSignal(int snum=0, bool block=1)
XrdClientThread(VoidRtnFunc_t fn)
Definition: XrdClientThread.hh:55
int SetCancelDeferred()
Definition: XrdClientThread.hh:96
static int SetCancelDeferred()
Definition: XrdSysPthread.hh:485
int SetCancelAsynchronous()
Definition: XrdClientThread.hh:93
static int Join(pthread_t tid, void **ret)
Definition: XrdSysPthread.hh:473
void * arg
Definition: XrdClientThread.hh:50
static int SetCancelAsynchronous()
Definition: XrdSysPthread.hh:481
static int SetCancelOn()
Definition: XrdSysPthread.hh:477
static int SetCancelOff()
Definition: XrdSysPthread.hh:469
void * XrdClientThreadDispatcher(void *arg)
void CancelPoint()
Definition: XrdClientThread.hh:99