xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdOuc
XrdOucCacheSlot.hh
Go to the documentation of this file.
1
#ifndef __XRDOUCCACHESLOT_HH__
2
#define __XRDOUCCACHESLOT_HH__
3
/******************************************************************************/
4
/* */
5
/* X r d O u c C a c h e S l o t . h h */
6
/* */
7
/* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8
/* All Rights Reserved */
9
/* Produced by Andrew Hanushevsky for Stanford University under contract */
10
/* DE-AC02-76-SFO0515 with the Department of Energy */
11
/* */
12
/* This file is part of the XRootD software suite. */
13
/* */
14
/* XRootD is free software: you can redistribute it and/or modify it under */
15
/* the terms of the GNU Lesser General Public License as published by the */
16
/* Free Software Foundation, either version 3 of the License, or (at your */
17
/* option) any later version. */
18
/* */
19
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22
/* License for more details. */
23
/* */
24
/* You should have received a copy of the GNU Lesser General Public License */
25
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27
/* */
28
/* The copyright holder's institutional names and contributor's names may not */
29
/* be used to endorse or promote products derived from this software without */
30
/* specific prior written permission of the institution or contributor. */
31
/******************************************************************************/
32
33
/* This class is used to support a memory cache used by an XrdOucCache actual
34
implementation.
35
*/
36
37
class
XrdOucCacheData
;
38
class
XrdOucCacheIO
;
39
class
XrdSysSemaphore
;
40
41
class
XrdOucCacheSlot
42
{
43
public
:
44
45
inline
void
File
(
XrdOucCacheIO
*kV,
int
you)
46
{
Status
.
Data
= 0;
Key
= kV;
HLink
= you;
Count
= 1;}
47
48
static
inline
int
Find
(
XrdOucCacheSlot
*Base,
long
long
What,
int
n)
49
{
while
(n && Base[n].
Contents
!= What) n=Base[n].
HLink
;
50
return
n;
51
}
52
53
inline
void
Hide
(
XrdOucCacheSlot
*Base,
int
*hTab,
int
hI)
54
{
int
j, Slot =
this
-Base;
55
if
(hTab[hI] == Slot) hTab[hI] =
HLink
;
56
else
if
((j = hTab[hI]))
57
{
while
((hI=Base[j].
HLink
) && hI != Slot) j=hI;
58
if
(hI) Base[j].
HLink
= Base[hI].
HLink
;
59
}
60
Count
= 0;
Contents
= -1;
61
}
62
63
static
void
Init
(
XrdOucCacheSlot
*Base,
int
Num)
64
{
int
i;
65
Base->
Status
.
LRU
.
Next
= Base->
Status
.
LRU
.
Prev
= 0;
66
Base->
Own
.
Next
= Base->
Own
.
Prev
= 0;
67
for
(i = 1; i < Num; i++)
68
{Base[i].
Status
.
LRU
.
Next
= Base[i].
Status
.
LRU
.
Prev
= i;
69
Base[i].
Own
.
Next
= Base[i].
Own
.
Prev
= i;
70
Base->
Push
(Base, &Base[i]);
71
}
72
}
73
74
inline
int
Pull
(
XrdOucCacheSlot
*Base)
75
{Base[
Status
.
LRU
.
Prev
].
Status
.
LRU
.
Next
=
Status
.
LRU
.
Next
;
76
Base[
Status
.
LRU
.
Next
].
Status
.
LRU
.
Prev
=
Status
.
LRU
.
Prev
;
77
Status
.
LRU
.
Next
=
Status
.
LRU
.
Prev
=
this
-Base;
78
return
Status
.
LRU
.
Next
;
79
}
80
81
inline
int
Push
(
XrdOucCacheSlot
*Base,
XrdOucCacheSlot
*sP)
82
{
int
UrNum = sP-Base, MyNum =
this
-Base;
83
sP->
Status
.
LRU
.
Next
= MyNum;
84
sP->
Status
.
LRU
.
Prev
=
Status
.
LRU
.
Prev
;
85
Base[
Status
.
LRU
.
Prev
].Status.LRU.Next = UrNum;
86
Status
.
LRU
.
Prev
= UrNum;
87
return
UrNum;
88
}
89
90
inline
void
Owner
(
XrdOucCacheSlot
*Base)
91
{Base[
Own
.
Prev
].
Own
.
Next
=
Own
.
Next
;
92
Base[
Own
.
Next
].
Own
.
Prev
=
Own
.
Prev
;
93
Own
.
Next
=
Own
.
Prev
=
this
-Base;
94
}
95
96
inline
void
Owner
(
XrdOucCacheSlot
*Base,
XrdOucCacheSlot
*sP)
97
{
int
UrNum = sP-Base, MyNum =
this
-Base;
98
sP->
Own
.
Next
= MyNum; sP->
Own
.
Prev
=
Own
.
Prev
;
99
Base[
Own
.
Prev
].Own.Next = UrNum;
Own
.
Prev
= UrNum;
100
}
101
102
inline
void
reRef
(
XrdOucCacheSlot
*Base)
103
{
Status
.
LRU
.
Prev
= Base->
Status
.
LRU
.
Prev
;
104
Base[
Status
.
LRU
.
Prev
].
Status
.
LRU
.
Next
=
this
-Base;
105
Base->
Status
.
LRU
.
Prev
=
this
-Base;
106
Status
.
LRU
.
Next
= 0;
107
}
108
109
inline
void
unRef
(
XrdOucCacheSlot
*Base)
110
{
Status
.
LRU
.
Next
= Base->
Status
.
LRU
.
Next
;
111
Base [
Status
.
LRU
.
Next
].
Status
.
LRU
.
Prev
=
this
-Base;
112
Base->
Status
.
LRU
.
Next
=
this
-Base;
113
Status
.
LRU
.
Prev
= 0;
114
}
115
116
struct
SlotList
117
{
118
int
Next
;
119
int
Prev
;
120
};
121
122
struct
ioQ
123
{
ioQ
*
Next
;
124
XrdSysSemaphore
*
ioEnd
;
125
ioQ
(
ioQ
*First,
XrdSysSemaphore
*ioW)
126
:
Next
(First),
ioEnd
(ioW) {}
127
};
128
129
union
SlotState
130
{
struct
ioQ
*
waitQ
;
131
XrdOucCacheData
*
Data
;
132
struct
SlotList
LRU
;
133
int
inUse
;
134
};
135
136
union
{
long
long
Contents
;
137
XrdOucCacheIO
*
Key
;
138
};
139
SlotState
Status
;
140
SlotList
Own
;
141
int
HLink
;
142
int
Count
;
143
144
static
const
int
lenMask
= 0x01ffffff;
// Mask to get true value in Count
145
static
const
int
isShort
= 0x80000000;
// Short page, Count & lenMask == size
146
static
const
int
inTrans
= 0x40000000;
// Segment is in transit
147
static
const
int
isSUSE
= 0x20000000;
// Segment is single use
148
static
const
int
isNew
= 0x10000000;
// Segment is new (not yet referenced)
149
150
XrdOucCacheSlot
() :
Contents
(-1),
HLink
(0),
Count
(0) {}
151
152
~XrdOucCacheSlot
() {}
153
};
154
#endif
Generated by
1.8.3.1