Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:52

0001 #ifndef __XrdBuffer_H__
0002 #define __XrdBuffer_H__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                          X r d B u f f e r . h h                           */
0006 /*                                                                            */
0007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0010 /*                                                                            */
0011 /* This file is part of the XRootD software suite.                            */
0012 /*                                                                            */
0013 /* XRootD is free software: you can redistribute it and/or modify it under    */
0014 /* the terms of the GNU Lesser General Public License as published by the     */
0015 /* Free Software Foundation, either version 3 of the License, or (at your     */
0016 /* option) any later version.                                                 */
0017 /*                                                                            */
0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0021 /* License for more details.                                                  */
0022 /*                                                                            */
0023 /* You should have received a copy of the GNU Lesser General Public License   */
0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0026 /*                                                                            */
0027 /* The copyright holder's institutional names and contributor's names may not */
0028 /* be used to endorse or promote products derived from this software without  */
0029 /* specific prior written permission of the institution or contributor.       */
0030 /******************************************************************************/
0031 
0032 #include <cstdlib>
0033 #include <unistd.h>
0034 #include <sys/types.h>
0035 #include "XrdSys/XrdSysPthread.hh"
0036 
0037 /******************************************************************************/
0038 /*                            x r d _ B u f f e r                             */
0039 /******************************************************************************/
0040 
0041 class XrdBuffer
0042 {
0043 public:
0044 
0045 char *   buff;     // -> buffer
0046 int      bsize;    // size of this buffer
0047 
0048          XrdBuffer(char *bp, int sz, int ix)
0049                       {buff = bp; bsize = sz; bindex = ix; next = 0;}
0050 
0051         ~XrdBuffer() {if (buff) free(buff);}
0052 
0053          friend class XrdBuffManager;
0054          friend class XrdBuffXL;
0055 private:
0056 
0057 int        bindex;
0058 XrdBuffer *next;
0059 static int pagesz;
0060 };
0061   
0062 /******************************************************************************/
0063 /*                       x r d _ B u f f M a n a g e r                        */
0064 /******************************************************************************/
0065 
0066 #define XRD_BUCKETS 12
0067 #define XRD_BUSHIFT 10
0068 
0069 // There should be only one instance of this class per buffer pool.
0070 //
0071 class XrdBuffManager
0072 {
0073 public:
0074 
0075 void        Init();
0076 
0077 XrdBuffer  *Obtain(int bsz);
0078 
0079 int         Recalc(int bsz);
0080 
0081 void        Release(XrdBuffer *bp);
0082 
0083 int         MaxSize() {return maxsz;}
0084 
0085 void        Reshape();
0086 
0087 void        Set(int maxmem=-1, int minw=-1);
0088 
0089 int         Stats(char *buff, int blen, int do_sync=0);
0090 
0091             XrdBuffManager(int minrst=20*60);
0092 
0093            ~XrdBuffManager();   // The buffmanager is never deleted
0094 
0095 private:
0096 
0097 const int  slots;
0098 const int  shift;
0099 const int  pagsz;
0100 const int  maxsz;
0101 
0102 struct {XrdBuffer *bnext;
0103         int         numbuf;
0104         int         numreq;
0105        } bucket[XRD_BUCKETS];          // 1K to 1<<(szshift+slots-1)M buffers
0106 
0107 int       totreq;
0108 int       totbuf;
0109 long long totalo;
0110 long long maxalo;
0111 int       minrsw;
0112 int       rsinprog;
0113 int       totadj;
0114 
0115 XrdSysCondVar      Reshaper;
0116 static const char *TraceID;
0117 };
0118 #endif