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 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <sys/types.h>
35 #include "XrdSys/XrdSysPthread.hh"
36 
37 /******************************************************************************/
38 /* x r d _ B u f f e r */
39 /******************************************************************************/
40 
41 class XrdBuffer
42 {
43 public:
44 
45 char * buff; // -> buffer
46 int bsize; // size of this buffer
47 
48  XrdBuffer(char *bp, int sz, int ix)
49  {buff = bp; bsize = sz; bindex = ix; next = 0;}
50 
51  ~XrdBuffer() {if (buff) free(buff);}
52 
53  friend class XrdBuffManager;
54  friend class XrdBuffXL;
55 private:
56 
57 int bindex;
59 static int pagesz;
60 };
61 
62 /******************************************************************************/
63 /* x r d _ B u f f M a n a g e r */
64 /******************************************************************************/
65 
66 #define XRD_BUCKETS 12
67 #define XRD_BUSHIFT 10
68 
69 // There should be only one instance of this class per buffer pool.
70 //
71 class XrdOucTrace;
72 class XrdSysError;
73 
75 {
76 public:
77 
78 void Init();
79 
80 XrdBuffer *Obtain(int bsz);
81 
82 int Recalc(int bsz);
83 
84 void Release(XrdBuffer *bp);
85 
86 int MaxSize() {return maxsz;}
87 
88 void Reshape();
89 
90 void Set(int maxmem=-1, int minw=-1);
91 
92 int Stats(char *buff, int blen, int do_sync=0);
93 
94  XrdBuffManager(XrdSysError *lP, XrdOucTrace *tP, int minrst=20*60);
95 
96  ~XrdBuffManager(); // The buffmanager is never deleted
97 
98 private:
99 
102 
103 const int slots;
104 const int shift;
105 const int pagsz;
106 const int maxsz;
107 
108 struct {XrdBuffer *bnext;
109  int numbuf;
110  int numreq;
111  } bucket[XRD_BUCKETS]; // 1K to 1<<(szshift+slots-1)M buffers
112 
113 int totreq;
114 int totbuf;
115 long long totalo;
116 long long maxalo;
117 int minrsw;
119 int totadj;
120 
122 static const char *TraceID;
123 };
124 #endif
#define XRD_BUCKETS
Definition: XrdBuffer.hh:66
XrdBuffManager(XrdSysError *lP, XrdOucTrace *tP, int minrst=20 *60)
long long maxalo
Definition: XrdBuffer.hh:116
int totbuf
Definition: XrdBuffer.hh:114
int MaxSize()
Definition: XrdBuffer.hh:86
XrdBuffer * next
Definition: XrdBuffer.hh:58
long long totalo
Definition: XrdBuffer.hh:115
int numbuf
Definition: XrdBuffer.hh:109
void Set(int maxmem=-1, int minw=-1)
XrdBuffer * bnext
Definition: XrdBuffer.hh:108
XrdBuffer * Obtain(int bsz)
XrdSysError * XrdLog
Definition: XrdBuffer.hh:101
int totreq
Definition: XrdBuffer.hh:113
static int pagesz
Definition: XrdBuffer.hh:59
int bindex
Definition: XrdBuffer.hh:57
Definition: XrdBuffer.hh:74
Definition: XrdOucTrace.hh:35
Definition: XrdSysError.hh:89
XrdOucTrace * XrdTrace
Definition: XrdBuffer.hh:100
int bsize
Definition: XrdBuffer.hh:46
const int maxsz
Definition: XrdBuffer.hh:106
Definition: XrdSysPthread.hh:53
int totadj
Definition: XrdBuffer.hh:119
const int shift
Definition: XrdBuffer.hh:104
int Stats(char *buff, int blen, int do_sync=0)
~XrdBuffer()
Definition: XrdBuffer.hh:51
char * buff
Definition: XrdBuffer.hh:45
void Release(XrdBuffer *bp)
friend class XrdBuffXL
Definition: XrdBuffer.hh:54
int Recalc(int bsz)
int numreq
Definition: XrdBuffer.hh:110
const int slots
Definition: XrdBuffer.hh:103
struct XrdBuffManager::@0 bucket[XRD_BUCKETS]
XrdSysCondVar Reshaper
Definition: XrdBuffer.hh:121
int minrsw
Definition: XrdBuffer.hh:117
const int pagsz
Definition: XrdBuffer.hh:105
static const char * TraceID
Definition: XrdBuffer.hh:122
int rsinprog
Definition: XrdBuffer.hh:118
XrdBuffer(char *bp, int sz, int ix)
Definition: XrdBuffer.hh:48
Definition: XrdBuffer.hh:41