00001 #ifndef ___XRD_SCHED_H___
00002 #define ___XRD_SCHED_H___
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <unistd.h>
00033 #include <sys/types.h>
00034
00035 #include "XrdSys/XrdSysPthread.hh"
00036 #include "Xrd/XrdJob.hh"
00037
00038 class XrdOucTrace;
00039 class XrdSchedulerPID;
00040 class XrdSysError;
00041
00042 class XrdScheduler : public XrdJob
00043 {
00044 public:
00045
00046 int Active() {return num_Workers - idl_Workers + num_JobsinQ;}
00047
00048 void Cancel(XrdJob *jp);
00049
00050 inline int canStick() {return num_Workers < stk_Workers
00051 || (num_Workers-idl_Workers) < stk_Workers;}
00052
00053 void DoIt();
00054
00055 pid_t Fork(const char *id);
00056
00057 void *Reaper();
00058
00059 void Run();
00060
00061 void Schedule(XrdJob *jp);
00062 void Schedule(int num, XrdJob *jfirst, XrdJob *jlast);
00063 void Schedule(XrdJob *jp, time_t atime);
00064
00065 void setParms(int minw, int maxw, int avlt, int maxi, int once=0);
00066
00067 void Start();
00068
00069 int Stats(char *buff, int blen, int do_sync=0);
00070
00071 void TimeSched();
00072
00073
00074
00075 int num_TCreate;
00076 int num_TDestroy;
00077 int num_Jobs;
00078 int max_QLength;
00079 int num_Limited;
00080
00081
00082
00083 XrdScheduler(XrdSysError *eP, XrdOucTrace *tP,
00084 int minw=8, int maxw=8192, int maxi=780);
00085
00086 ~XrdScheduler();
00087
00088 private:
00089 XrdSysError *XrdLog;
00090 XrdOucTrace *XrdTrace;
00091
00092 XrdSysMutex DispatchMutex;
00093 int idl_Workers;
00094
00095 int min_Workers;
00096 int max_Workers;
00097 int max_Workidl;
00098 int num_Workers;
00099 int stk_Workers;
00100 int num_JobsinQ;
00101 int num_Layoffs;
00102
00103 XrdJob *WorkFirst;
00104 XrdJob *WorkLast;
00105 XrdSysSemaphore WorkAvail;
00106 XrdSysMutex SchedMutex;
00107
00108 XrdJob *TimerQueue;
00109 XrdSysCondVar TimerRings;
00110 XrdSysMutex TimerMutex;
00111
00112 XrdSchedulerPID *firstPID;
00113 XrdSysMutex ReaperMutex;
00114
00115 void hireWorker(int dotrace=1);
00116 void Monitor();
00117 void traceExit(pid_t pid, int status);
00118 static const char *TraceID;
00119 };
00120 #endif