XrdBwmPolicy1.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                      X r d B w m P o l i c y 1 . c c                       */
00004 /*                                                                            */
00005 /* (c) 2008 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010   
00011 //         $Id: XrdBwmPolicy1.cc 30949 2009-11-02 16:37:58Z ganis $
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 /*                           C o n s t r u c t o r                            */
00021 /******************************************************************************/
00022   
00023 XrdBwmPolicy1::XrdBwmPolicy1(int inslots, int outslots)
00024 {
00025 // Initialize values
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 /*                              D i s p a t c h                               */
00035 /******************************************************************************/
00036   
00037 int  XrdBwmPolicy1::Dispatch(char *RespBuff, int RespSize)
00038 {
00039    refReq *rP;
00040    int     rID;
00041 
00042 // Obtain mutex and check if we have any queued requests
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 // Should never get here
00056 //
00057    strcpy(RespBuff, "Fatal logic error!");
00058    return 0;
00059 }
00060 
00061 /******************************************************************************/
00062 /*                                  D o n e                                   */
00063 /******************************************************************************/
00064   
00065 int  XrdBwmPolicy1::Done(int rHandle)
00066 {
00067    refReq *rP;
00068    int rc;
00069 
00070 // Make sure we have a positive value here
00071 //
00072    if (rHandle < 0) rHandle = -rHandle;
00073 
00074 // Remove the element from whichever queue it is in
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 // delete the element and return
00087 //
00088    if (rP) delete rP;
00089    return rc;
00090 }
00091 
00092 /******************************************************************************/
00093 /*                              S c h e d u l e                               */
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 // Get the global lock and generate a reference ID
00103 //
00104    *RespBuff = '\0';
00105    pMutex.Lock();
00106    myID = ++refID;
00107    rP = new refReq(myID, Parms.Direction);
00108 
00109 // Check if we can immediately schedule this requestor must defer it
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 // All done
00124 //
00125    pMutex.UnLock();
00126    return myID;
00127 }
00128 
00129 /******************************************************************************/
00130 /*                                S t a t u s                                 */
00131 /******************************************************************************/
00132   
00133 void XrdBwmPolicy1::Status(int &numqIn, int &numqOut, int &numXeq)
00134 {
00135 
00136 // Get the global lock and return the values
00137 //
00138    pMutex.Lock();
00139    numqIn  = theQ[In ].Num;
00140    numqOut = theQ[Out].Num;
00141    numXeq  = theQ[Xeq].Num;
00142    pMutex.UnLock();
00143 }

Generated on Tue Jul 5 14:46:16 2011 for ROOT_528-00b_version by  doxygen 1.5.1