XRootD
Loading...
Searching...
No Matches
XrdXrootdPio.cc
Go to the documentation of this file.
1
/******************************************************************************/
2
/* */
3
/* X r d X r o o t d P i o . c c */
4
/* */
5
/* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
6
/* All Rights Reserved */
7
/* Produced by Andrew Hanushevsky for Stanford University under contract */
8
/* DE-AC02-76-SFO0515 with the Department of Energy */
9
/* */
10
/* This file is part of the XRootD software suite. */
11
/* */
12
/* XRootD is free software: you can redistribute it and/or modify it under */
13
/* the terms of the GNU Lesser General Public License as published by the */
14
/* Free Software Foundation, either version 3 of the License, or (at your */
15
/* option) any later version. */
16
/* */
17
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20
/* License for more details. */
21
/* */
22
/* You should have received a copy of the GNU Lesser General Public License */
23
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25
/* */
26
/* The copyright holder's institutional names and contributor's names may not */
27
/* be used to endorse or promote products derived from this software without */
28
/* specific prior written permission of the institution or contributor. */
29
/******************************************************************************/
30
31
#include "
XrdXrootd/XrdXrootdPio.hh
"
32
33
/******************************************************************************/
34
/* S t a t i c V a r i a b l e s */
35
/******************************************************************************/
36
37
XrdSysMutex
XrdXrootdPio::myMutex;
38
XrdXrootdPio
*XrdXrootdPio::Free = 0;
39
int
XrdXrootdPio::FreeNum = 0;
40
41
/******************************************************************************/
42
/* A l l o c */
43
/******************************************************************************/
44
45
XrdXrootdPio
*
XrdXrootdPio::Alloc
(
int
Num)
46
{
47
XrdXrootdPio
*lqp, *qp=0;
48
49
50
// Allocate from the free stack
51
//
52
myMutex.Lock();
53
if
((qp = Free))
54
{
do
{FreeNum--; Num--; lqp = Free;}
55
while
((Free = Free->Next) && Num);
56
lqp->
Next
= 0;
57
}
58
myMutex.UnLock();
59
60
// Allocate additional if we have not allocated enough
61
//
62
while
(Num--) qp =
new
XrdXrootdPio
(qp);
63
64
// All done
65
//
66
return
qp;
67
}
68
69
/******************************************************************************/
70
/* R e c y c l e */
71
/******************************************************************************/
72
73
void
XrdXrootdPio::Recycle
()
74
{
75
76
// Check if we can hold on to this or must delete it
77
//
78
myMutex.Lock();
79
if
(FreeNum >= FreeMax) {myMutex.UnLock();
delete
this
;
return
;}
80
81
// Clean this up and push the element on the free stack
82
//
83
Free =
Clear
(Free); FreeNum++;
84
myMutex.UnLock();
85
}
XrdXrootdPio.hh
XrdSysMutex
Definition
XrdSysPthread.hh:165
XrdXrootdPio
Definition
XrdXrootdPio.hh:40
XrdXrootdPio::Next
XrdXrootdPio * Next
Definition
XrdXrootdPio.hh:43
XrdXrootdPio::Recycle
void Recycle()
Definition
XrdXrootdPio.cc:73
XrdXrootdPio::XrdXrootdPio
XrdXrootdPio(XrdXrootdPio *np=0)
Definition
XrdXrootdPio.hh:66
XrdXrootdPio::Alloc
static XrdXrootdPio * Alloc(int n=1)
Definition
XrdXrootdPio.cc:45
XrdXrootdPio::Clear
XrdXrootdPio * Clear(XrdXrootdPio *np=0)
Definition
XrdXrootdPio.hh:50
XrdXrootd
XrdXrootdPio.cc
Generated by
1.14.0