XrdXrootdPio.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                       X r d X r o o t d P i o . c c                        */
00004 /*                                                                            */
00005 /* (c) 2007 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: XrdXrootdPio.cc 30949 2009-11-02 16:37:58Z ganis $
00012 
00013 const char *XrdXrootdPioCVSID = "$Id: XrdXrootdPio.cc 30949 2009-11-02 16:37:58Z ganis $";
00014   
00015 #include "XrdXrootd/XrdXrootdPio.hh"
00016 
00017 /******************************************************************************/
00018 /*                      S t a t i c   V a r i a b l e s                       */
00019 /******************************************************************************/
00020   
00021 XrdSysMutex        XrdXrootdPio::myMutex;
00022 XrdXrootdPio      *XrdXrootdPio::Free = 0;
00023 int                XrdXrootdPio::FreeNum = 0;
00024 
00025 /******************************************************************************/
00026 /*                                 A l l o c                                  */
00027 /******************************************************************************/
00028   
00029 XrdXrootdPio *XrdXrootdPio::Alloc(int Num)
00030 {
00031    XrdXrootdPio *lqp, *qp=0;
00032 
00033 
00034 // Allocate from the free stack
00035 //
00036    myMutex.Lock();
00037    if ((qp = Free))
00038       {do {FreeNum--; Num--; lqp = Free;}
00039           while((Free = Free->Next) && Num);
00040        lqp->Next = 0;
00041       }
00042    myMutex.UnLock();
00043 
00044 // Allocate additional if we have not allocated enough
00045 //
00046    while(Num--) qp = new XrdXrootdPio(qp);
00047 
00048 // All done
00049 //
00050    return qp;
00051 }
00052 
00053 /******************************************************************************/
00054 /*                               R e c y c l e                                */
00055 /******************************************************************************/
00056   
00057 void XrdXrootdPio::Recycle()
00058 {
00059 
00060 // Check if we can hold on to this or must delete it
00061 //
00062    myMutex.Lock();
00063    if (FreeNum >= FreeMax) {myMutex.UnLock(); delete this; return;}
00064 
00065 // Clean this up and push the element on the free stack
00066 //
00067    Free = Clear(Free); FreeNum++;
00068    myMutex.UnLock();
00069 }

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