xrootd
XrdBuffer.hh
Go to the documentation of this file.
1 #ifndef __XrdBuffer_H__
2 #define __XrdBuffer_H__
3 /******************************************************************************/
4 /* */
5 /* X r d B u f f e r . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <sys/types.h>
16 #include "XrdSys/XrdSysPthread.hh"
17 
18 /******************************************************************************/
19 /* x r d _ B u f f e r */
20 /******************************************************************************/
21 
22 class XrdBuffer
23 {
24 public:
25 
26 char * buff; // -> buffer
27 int bsize; // size of this buffer
28 
29  XrdBuffer(char *bp, int sz, int ix)
30  {buff = bp; bsize = sz; bindex = ix; next = 0;}
31 
32  ~XrdBuffer() {if (buff) free(buff);}
33 
34  friend class XrdBuffManager;
35 private:
36 
38  int bindex;
39 static int pagesz;
40 };
41 
42 /******************************************************************************/
43 /* x r d _ B u f f M a n a g e r */
44 /******************************************************************************/
45 
46 #define XRD_BUCKETS 12
47 #define XRD_BUSHIFT 10
48 
49 // There should be only one instance of this class per buffer pool.
50 //
51 class XrdOucTrace;
52 class XrdSysError;
53 
55 {
56 public:
57 
58 void Init();
59 
60 XrdBuffer *Obtain(int bsz);
61 
62 int Recalc(int bsz);
63 
64 void Release(XrdBuffer *bp);
65 
66 int MaxSize() {return maxsz;}
67 
68 void Reshape();
69 
70 void Set(int maxmem=-1, int minw=-1);
71 
72 int Stats(char *buff, int blen, int do_sync=0);
73 
74  XrdBuffManager(XrdSysError *lP, XrdOucTrace *tP, int minrst=20*60);
75 
76  ~XrdBuffManager() {} // The buffmanager is never deleted
77 
78 private:
79 
82 
83 const int slots;
84 const int shift;
85 const int pagsz;
86 const int maxsz;
87 
88 struct {XrdBuffer *bnext;
89  int numbuf;
90  int numreq;
91  } bucket[XRD_BUCKETS]; // 1K to 1<<(szshift+slots-1)M buffers
92 
93 int totreq;
94 int totbuf;
95 long long totalo;
96 long long maxalo;
97 int minrsw;
99 int totadj;
100 
102 static const char *TraceID;
103 };
104 #endif