XrdBuffer.hh

Go to the documentation of this file.
00001 #ifndef __XrdBuffer_H__
00002 #define __XrdBuffer_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X r d B u f f e r . h h                           */
00006 /*                                                                            */
00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00010 /*                                                                            */
00011 /* This file is part of the XRootD software suite.                            */
00012 /*                                                                            */
00013 /* XRootD is free software: you can redistribute it and/or modify it under    */
00014 /* the terms of the GNU Lesser General Public License as published by the     */
00015 /* Free Software Foundation, either version 3 of the License, or (at your     */
00016 /* option) any later version.                                                 */
00017 /*                                                                            */
00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00021 /* License for more details.                                                  */
00022 /*                                                                            */
00023 /* You should have received a copy of the GNU Lesser General Public License   */
00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00026 /*                                                                            */
00027 /* The copyright holder's institutional names and contributor's names may not */
00028 /* be used to endorse or promote products derived from this software without  */
00029 /* specific prior written permission of the institution or contributor.       */
00030 /******************************************************************************/
00031 
00032 #include <stdlib.h>
00033 #include <unistd.h>
00034 #include <sys/types.h>
00035 #include "XrdSys/XrdSysPthread.hh"
00036 
00037 /******************************************************************************/
00038 /*                            x r d _ B u f f e r                             */
00039 /******************************************************************************/
00040 
00041 class XrdBuffer
00042 {
00043 public:
00044 
00045 char *   buff;     // -> buffer
00046 int      bsize;    // size of this buffer
00047 
00048          XrdBuffer(char *bp, int sz, int ix)
00049                       {buff = bp; bsize = sz; bindex = ix; next = 0;}
00050 
00051         ~XrdBuffer() {if (buff) free(buff);}
00052 
00053          friend class XrdBuffManager;
00054 private:
00055 
00056 XrdBuffer *next;
00057        int  bindex;
00058 static int  pagesz;
00059 };
00060   
00061 /******************************************************************************/
00062 /*                       x r d _ B u f f M a n a g e r                        */
00063 /******************************************************************************/
00064 
00065 #define XRD_BUCKETS 12
00066 #define XRD_BUSHIFT 10
00067 
00068 // There should be only one instance of this class per buffer pool.
00069 //
00070 class XrdOucTrace;
00071 class XrdSysError;
00072   
00073 class XrdBuffManager
00074 {
00075 public:
00076 
00077 void        Init();
00078 
00079 XrdBuffer  *Obtain(int bsz);
00080 
00081 int         Recalc(int bsz);
00082 
00083 void        Release(XrdBuffer *bp);
00084 
00085 int         MaxSize() {return maxsz;}
00086 
00087 void        Reshape();
00088 
00089 void        Set(int maxmem=-1, int minw=-1);
00090 
00091 int         Stats(char *buff, int blen, int do_sync=0);
00092 
00093             XrdBuffManager(XrdSysError *lP, XrdOucTrace *tP, int minrst=20*60);
00094 
00095            ~XrdBuffManager() {} // The buffmanager is never deleted
00096 
00097 private:
00098 
00099 XrdOucTrace *XrdTrace;
00100 XrdSysError *XrdLog;
00101 
00102 const int  slots;
00103 const int  shift;
00104 const int  pagsz;
00105 const int  maxsz;
00106 
00107 struct {XrdBuffer *bnext;
00108         int         numbuf;
00109         int         numreq;
00110        } bucket[XRD_BUCKETS];          // 1K to 1<<(szshift+slots-1)M buffers
00111 
00112 int       totreq;
00113 int       totbuf;
00114 long long totalo;
00115 long long maxalo;
00116 int       minrsw;
00117 int       rsinprog;
00118 int       totadj;
00119 
00120 XrdSysCondVar      Reshaper;
00121 static const char *TraceID;
00122 };
00123 #endif

Generated on 16 Jan 2014 for xrootd by  doxygen 1.4.7