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          friend class XrdBuffXL;
00055 private:
00056 
00057 int        bindex;
00058 XrdBuffer *next;
00059 static int pagesz;
00060 };
00061   
00062 /******************************************************************************/
00063 /*                       x r d _ B u f f M a n a g e r                        */
00064 /******************************************************************************/
00065 
00066 #define XRD_BUCKETS 12
00067 #define XRD_BUSHIFT 10
00068 
00069 // There should be only one instance of this class per buffer pool.
00070 //
00071 class XrdOucTrace;
00072 class XrdSysError;
00073   
00074 class XrdBuffManager
00075 {
00076 public:
00077 
00078 void        Init();
00079 
00080 XrdBuffer  *Obtain(int bsz);
00081 
00082 int         Recalc(int bsz);
00083 
00084 void        Release(XrdBuffer *bp);
00085 
00086 int         MaxSize() {return maxsz;}
00087 
00088 void        Reshape();
00089 
00090 void        Set(int maxmem=-1, int minw=-1);
00091 
00092 int         Stats(char *buff, int blen, int do_sync=0);
00093 
00094             XrdBuffManager(XrdSysError *lP, XrdOucTrace *tP, int minrst=20*60);
00095 
00096            ~XrdBuffManager() {} // The buffmanager is never deleted
00097 
00098 private:
00099 
00100 XrdOucTrace *XrdTrace;
00101 XrdSysError *XrdLog;
00102 
00103 const int  slots;
00104 const int  shift;
00105 const int  pagsz;
00106 const int  maxsz;
00107 
00108 struct {XrdBuffer *bnext;
00109         int         numbuf;
00110         int         numreq;
00111        } bucket[XRD_BUCKETS];          // 1K to 1<<(szshift+slots-1)M buffers
00112 
00113 int       totreq;
00114 int       totbuf;
00115 long long totalo;
00116 long long maxalo;
00117 int       minrsw;
00118 int       rsinprog;
00119 int       totadj;
00120 
00121 XrdSysCondVar      Reshaper;
00122 static const char *TraceID;
00123 };
00124 #endif

Generated on 5 Oct 2016 for xrootd by  doxygen 1.4.7