XRootD
Loading...
Searching...
No Matches
XrdCmsRRData.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d C m s R R D a t a . 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 <unistd.h>
32
34
37
38using namespace XrdCms;
39
40/******************************************************************************/
41/* g e t B u f f */
42/******************************************************************************/
43
44int XrdCmsRRData::getBuff(size_t bsz)
45{
46 static size_t PageSize = sysconf(_SC_PAGESIZE);
47 size_t Alignment = PageSize;
48
49 if (bsz < Alignment)
50 {if (bsz <= 8) Alignment = bsz = 8;
51 else {do {Alignment = Alignment >> 1;} while(bsz < Alignment);
52 Alignment = Alignment << 1; bsz = Alignment;
53 }
54 }
55
56 if (Buff) free(Buff);
57 if (posix_memalign((void **)&Buff, Alignment, bsz))
58 {Buff = 0; return 0;}
59
60 Blen = bsz;
61 return 1;
62}
63
64/******************************************************************************/
65/* O b j e c t i f y */
66/******************************************************************************/
67
69{
70 static XrdSysMutex myMutex;
71 static XrdCmsRRData *Free;
72
73// Obtain a new object or recycle an old one
74//
75 myMutex.Lock();
76 if (op) {op->Next = Free; Free = op; op = 0;}
77 else {if ((op = Free)) Free = op->Next;
78 else {op = new XrdCmsRRData; op->Buff = 0; op->Blen = 0;}
79 op->Ident = 0; op->Next = 0;
80 }
81
82 myMutex.UnLock();
83
84 return op;
85}
static XrdCmsRRData * Objectify(XrdCmsRRData *op=0)
XrdCmsRRData * Next
int getBuff(size_t bsz)