00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 const char *XrdBwmPolicy1CVSID = "$Id: XrdBwmPolicy1.cc 30949 2009-11-02 16:37:58Z ganis $";
00014
00015 #include <string.h>
00016
00017 #include "XrdBwm/XrdBwmPolicy1.hh"
00018
00019
00020
00021
00022
00023 XrdBwmPolicy1::XrdBwmPolicy1(int inslots, int outslots)
00024 {
00025
00026
00027 theQ[In ].maxSlots = theQ[In ].curSlots = inslots;
00028 theQ[Out].maxSlots = theQ[Out].curSlots = outslots;
00029 theQ[Xeq].maxSlots = theQ[Xeq].curSlots = 0;
00030 refID = 1;
00031 }
00032
00033
00034
00035
00036
00037 int XrdBwmPolicy1::Dispatch(char *RespBuff, int RespSize)
00038 {
00039 refReq *rP;
00040 int rID;
00041
00042
00043
00044 do {pMutex.Lock();
00045 if ((rP = theQ[In].Next()) || (rP = theQ[Out].Next()))
00046 {theQ[Xeq].Add(rP);
00047 rID = rP->refID; *RespBuff = '\0';
00048 pMutex.UnLock();
00049 return refID;
00050 }
00051 pMutex.UnLock();
00052 pSem.Wait();
00053 } while(1);
00054
00055
00056
00057 strcpy(RespBuff, "Fatal logic error!");
00058 return 0;
00059 }
00060
00061
00062
00063
00064
00065 int XrdBwmPolicy1::Done(int rHandle)
00066 {
00067 refReq *rP;
00068 int rc;
00069
00070
00071
00072 if (rHandle < 0) rHandle = -rHandle;
00073
00074
00075
00076 pMutex.Lock();
00077 if ((rP = theQ[Xeq].Yank(rHandle)))
00078 {if (theQ[rP->Way].curSlots++ == 0) pSem.Post();
00079 rc = 1;
00080 } else {
00081 if ((rP=theQ[In].Yank(rHandle)) || (rP=theQ[Out].Yank(rHandle))) rc = -1;
00082 else rc = 0;
00083 }
00084 pMutex.UnLock();
00085
00086
00087
00088 if (rP) delete rP;
00089 return rc;
00090 }
00091
00092
00093
00094
00095
00096 int XrdBwmPolicy1::Schedule(char *RespBuff, int RespSize, SchedParms &Parms)
00097 {
00098 static const char *theWay[] = {"Incomming", "Outgoing"};
00099 refReq *rP;
00100 int myID;
00101
00102
00103
00104 *RespBuff = '\0';
00105 pMutex.Lock();
00106 myID = ++refID;
00107 rP = new refReq(myID, Parms.Direction);
00108
00109
00110
00111 if (theQ[rP->Way].curSlots > 0)
00112 {theQ[rP->Way].curSlots--;
00113 theQ[Xeq].Add(rP);
00114 }
00115 else if (theQ[rP->Way].maxSlots)
00116 {theQ[rP->Way].Add(rP); myID = -myID;}
00117 else {strcpy(RespBuff, theWay[rP->Way]);
00118 strcat(RespBuff, " requests are not allowed.");
00119 delete rP;
00120 myID = 0;
00121 }
00122
00123
00124
00125 pMutex.UnLock();
00126 return myID;
00127 }
00128
00129
00130
00131
00132
00133 void XrdBwmPolicy1::Status(int &numqIn, int &numqOut, int &numXeq)
00134 {
00135
00136
00137
00138 pMutex.Lock();
00139 numqIn = theQ[In ].Num;
00140 numqOut = theQ[Out].Num;
00141 numXeq = theQ[Xeq].Num;
00142 pMutex.UnLock();
00143 }