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