xrootd
|
00001 #ifndef __BWM_POLICY1_HH__ 00002 #define __BWM_POLICY1_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d B w m P o l i c y 1 . h h */ 00006 /* */ 00007 /* (c) 2008 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id$ 00014 00015 #include "XrdBwm/XrdBwmPolicy.hh" 00016 #include "XrdSys/XrdSysPthread.hh" 00017 00018 class XrdBwmPolicy1 : public XrdBwmPolicy 00019 { 00020 public: 00021 00022 int Dispatch(char *RespBuff, int RespSize); 00023 00024 int Done(int rHandle); 00025 00026 int Schedule(char *RespBuff, int RespSize, SchedParms &Parms); 00027 00028 void Status(int &numqIn, int &numqOut, int &numXeq); 00029 00030 XrdBwmPolicy1(int inslots, int outslots); 00031 ~XrdBwmPolicy1() {} 00032 00033 enum Flow {In = 0, Out = 1, Xeq = 2, IOX = 3}; 00034 00035 struct refReq 00036 {refReq *Next; 00037 int refID; 00038 Flow Way; 00039 00040 refReq(int id, XrdBwmPolicy::Flow xF) : Next(0), refID(id), 00041 Way(xF == XrdBwmPolicy::Incomming ? In : Out) {} 00042 ~refReq() {} 00043 }; 00044 00045 private: 00046 00047 class refSch 00048 {public: 00049 00050 refReq *First; 00051 refReq *Last; 00052 int Num; 00053 int curSlots; 00054 int maxSlots; 00055 00056 void Add(refReq *rP) 00057 {if ((rP->Next = Last)) Last = rP; 00058 else First= Last = rP; 00059 Num++; 00060 } 00061 00062 refReq *Next() {refReq *rP; 00063 if ((rP = First) && curSlots) 00064 {if (!(First = First->Next)) Last = 0; 00065 Num--; curSlots--; 00066 } 00067 return rP; 00068 } 00069 00070 refReq *Yank(int rID) 00071 {refReq *pP = 0, *rP = First; 00072 while(rP && rID != rP->refID) {pP = rP; rP = rP->Next;} 00073 if (rP) 00074 {if (pP) pP->Next = rP->Next; 00075 else First = rP->Next; 00076 if (rP == Last) Last = pP; 00077 Num--; 00078 } 00079 return rP; 00080 } 00081 00082 refSch() : First(0), Last(0), Num(0) {} 00083 ~refSch() {} // Never deleted! 00084 } theQ[IOX]; 00085 00086 XrdSysSemaphore pSem; 00087 XrdSysMutex pMutex; 00088 int refID; 00089 }; 00090 #endif