xrootd
XrdBwmPolicy1.hh
Go to the documentation of this file.
1 #ifndef __BWM_POLICY1_HH__
2 #define __BWM_POLICY1_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d B w m P o l i c y 1 . h h */
6 /* */
7 /* (c) 2008 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 // $Id$
14 
15 #include "XrdBwm/XrdBwmPolicy.hh"
16 #include "XrdSys/XrdSysPthread.hh"
17 
19 {
20 public:
21 
22 int Dispatch(char *RespBuff, int RespSize);
23 
24 int Done(int rHandle);
25 
26 int Schedule(char *RespBuff, int RespSize, SchedParms &Parms);
27 
28 void Status(int &numqIn, int &numqOut, int &numXeq);
29 
30  XrdBwmPolicy1(int inslots, int outslots);
32 
33 enum Flow {In = 0, Out = 1, Xeq = 2, IOX = 3};
34 
35 struct refReq
37  int refID;
39 
40  refReq(int id, XrdBwmPolicy::Flow xF) : Next(0), refID(id),
41  Way(xF == XrdBwmPolicy::Incomming ? In : Out) {}
42  ~refReq() {}
43  };
44 
45 private:
46 
47 class refSch
48  {public:
49 
52  int Num;
53  int curSlots;
54  int maxSlots;
55 
56  void Add(refReq *rP)
57  {if ((rP->Next = Last)) Last = rP;
58  else First= Last = rP;
59  Num++;
60  }
61 
62  refReq *Next() {refReq *rP;
63  if ((rP = First) && curSlots)
64  {if (!(First = First->Next)) Last = 0;
65  Num--; curSlots--;
66  }
67  return rP;
68  }
69 
70  refReq *Yank(int rID)
71  {refReq *pP = 0, *rP = First;
72  while(rP && rID != rP->refID) {pP = rP; rP = rP->Next;}
73  if (rP)
74  {if (pP) pP->Next = rP->Next;
75  else First = rP->Next;
76  if (rP == Last) Last = pP;
77  Num--;
78  }
79  return rP;
80  }
81 
82  refSch() : First(0), Last(0), Num(0) {}
83  ~refSch() {} // Never deleted!
84  } theQ[IOX];
85 
88 int refID;
89 };
90 #endif