|
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 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include "XrdBwm/XrdBwmPolicy.hh" 00034 #include "XrdSys/XrdSysPthread.hh" 00035 00036 class XrdBwmPolicy1 : public XrdBwmPolicy 00037 { 00038 public: 00039 00040 int Dispatch(char *RespBuff, int RespSize); 00041 00042 int Done(int rHandle); 00043 00044 int Schedule(char *RespBuff, int RespSize, SchedParms &Parms); 00045 00046 void Status(int &numqIn, int &numqOut, int &numXeq); 00047 00048 XrdBwmPolicy1(int inslots, int outslots); 00049 ~XrdBwmPolicy1() {} 00050 00051 enum Flow {In = 0, Out = 1, Xeq = 2, IOX = 3}; 00052 00053 struct refReq 00054 {refReq *Next; 00055 int refID; 00056 Flow Way; 00057 00058 refReq(int id, XrdBwmPolicy::Flow xF) : Next(0), refID(id), 00059 Way(xF == XrdBwmPolicy::Incomming ? In : Out) {} 00060 ~refReq() {} 00061 }; 00062 00063 private: 00064 00065 class refSch 00066 {public: 00067 00068 refReq *First; 00069 refReq *Last; 00070 int Num; 00071 int curSlots; 00072 int maxSlots; 00073 00074 void Add(refReq *rP) 00075 {if ((rP->Next = Last)) Last = rP; 00076 else First= Last = rP; 00077 Num++; 00078 } 00079 00080 refReq *Next() {refReq *rP; 00081 if ((rP = First) && curSlots) 00082 {if (!(First = First->Next)) Last = 0; 00083 Num--; curSlots--; 00084 } 00085 return rP; 00086 } 00087 00088 refReq *Yank(int rID) 00089 {refReq *pP = 0, *rP = First; 00090 while(rP && rID != rP->refID) {pP = rP; rP = rP->Next;} 00091 if (rP) 00092 {if (pP) pP->Next = rP->Next; 00093 else First = rP->Next; 00094 if (rP == Last) Last = pP; 00095 Num--; 00096 } 00097 return rP; 00098 } 00099 00100 refSch() : First(0), Last(0), Num(0) {} 00101 ~refSch() {} // Never deleted! 00102 } theQ[IOX]; 00103 00104 XrdSysSemaphore pSem; 00105 XrdSysMutex pMutex; 00106 int refID; 00107 }; 00108 #endif
1.7.6.1