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 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00011 /******************************************************************************/
00012 
00013 //          $Id: XrdBuffer.hh 22437 2008-03-04 14:35:16Z rdm $ 
00014 
00015 #include <stdlib.h>
00016 #include <unistd.h>
00017 #include <sys/types.h>
00018 #include "XrdSys/XrdSysPthread.hh"
00019 
00020 /******************************************************************************/
00021 /*                            x r d _ B u f f e r                             */
00022 /******************************************************************************/
00023 
00024 class XrdBuffer
00025 {
00026 public:
00027 
00028 char *   buff;     // -> buffer
00029 int      bsize;    // size of this buffer
00030 
00031          XrdBuffer(char *bp, int sz, int ix)
00032                       {buff = bp; bsize = sz; bindex = ix; next = 0;}
00033 
00034         ~XrdBuffer() {if (buff) free(buff);}
00035 
00036          friend class XrdBuffManager;
00037 private:
00038 
00039 XrdBuffer *next;
00040        int  bindex;
00041 static int  pagesz;
00042 };
00043   
00044 /******************************************************************************/
00045 /*                       x r d _ B u f f M a n a g e r                        */
00046 /******************************************************************************/
00047 
00048 #define XRD_BUCKETS 12
00049 #define XRD_BUSHIFT 10
00050 
00051 // There should be only one instance of this class per buffer pool.
00052 //
00053   
00054 class XrdBuffManager
00055 {
00056 public:
00057 
00058 void        Init();
00059 
00060 XrdBuffer  *Obtain(int bsz);
00061 
00062 int         Recalc(int bsz);
00063 
00064 void        Release(XrdBuffer *bp);
00065 
00066 int         MaxSize() {return maxsz;}
00067 
00068 void        Reshape();
00069 
00070 void        Set(int maxmem=-1, int minw=-1);
00071 
00072 int         Stats(char *buff, int blen, int do_sync=0);
00073 
00074             XrdBuffManager(int minrst=20*60);
00075 
00076            ~XrdBuffManager() {} // The buffmanager is never deleted
00077 
00078 private:
00079 
00080 const int  slots;
00081 const int  shift;
00082 const int  pagsz;
00083 const int  maxsz;
00084 
00085 struct {XrdBuffer *bnext;
00086         int         numbuf;
00087         int         numreq;
00088        } bucket[XRD_BUCKETS];          // 1K to 1<<(szshift+slots-1)M buffers
00089 
00090 int       totreq;
00091 int       totbuf;
00092 long long totalo;
00093 long long maxalo;
00094 int       minrsw;
00095 int       rsinprog;
00096 int       totadj;
00097 
00098 XrdSysCondVar      Reshaper;
00099 static const char *TraceID;
00100 };
00101 #endif

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