xrootd
Loading...
Searching...
No Matches
XrdRmcSlot.hh
Go to the documentation of this file.
1#ifndef __XRDRMCSLOT_HH__
2#define __XRDRMCSLOT_HH__
3/******************************************************************************/
4/* */
5/* X r d R m c S l o t . h h */
6/* */
7/* (c) 2019 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
37class XrdRmcData;
38class XrdOucCacheIO;
39class XrdSysSemaphore;
40
42{
43public:
44
45inline void File(XrdOucCacheIO *kV, int you)
46 {Status.Data = 0; Key = kV; HLink = you; Count = 1;}
47
48static inline int Find(XrdRmcSlot *Base, long long What, int n)
49 {while(n && Base[n].Contents != What) n=Base[n].HLink;
50 return n;
51 }
52
53inline void Hide(XrdRmcSlot *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
63static void Init(XrdRmcSlot *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
74inline int Pull(XrdRmcSlot *Base)
77 Status.LRU.Next = Status.LRU.Prev = this-Base;
78 return Status.LRU.Next;
79 }
80
81inline int Push(XrdRmcSlot *Base, XrdRmcSlot *sP)
82 {int UrNum = sP-Base, MyNum = this-Base;
83 sP->Status.LRU.Next = MyNum;
85 Base[Status.LRU.Prev].Status.LRU.Next = UrNum;
86 Status.LRU.Prev = UrNum;
87 return UrNum;
88 }
89
90inline void Owner(XrdRmcSlot *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
96inline void Owner(XrdRmcSlot *Base, XrdRmcSlot *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
102inline void reRef(XrdRmcSlot *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
109inline void unRef(XrdRmcSlot *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
117 {
118 int Next;
119 int Prev;
120 };
121
122struct ioQ
125 ioQ(ioQ *First, XrdSysSemaphore *ioW)
126 : Next(First), ioEnd(ioW) {}
127 };
128
130 {struct ioQ *waitQ;
132 struct SlotList LRU;
133 int inUse;
134 };
135
136union {long long Contents;
138 };
143
144static const int lenMask = 0x01ffffff; // Mask to get true value in Count
145static const int isShort = 0x80000000; // Short page, Count & lenMask == size
146static const int inTrans = 0x40000000; // Segment is in transit
147static const int isSUSE = 0x20000000; // Segment is single use
148static const int isNew = 0x10000000; // Segment is new (not yet referenced)
149
150 XrdRmcSlot() : Contents(-1), HLink(0), Count(0) {}
151
153};
154#endif
Definition XrdOucCache.hh:105
Definition XrdRmcData.hh:43
Definition XrdRmcSlot.hh:42
void File(XrdOucCacheIO *kV, int you)
Definition XrdRmcSlot.hh:45
void Owner(XrdRmcSlot *Base)
Definition XrdRmcSlot.hh:90
void unRef(XrdRmcSlot *Base)
Definition XrdRmcSlot.hh:109
int HLink
Definition XrdRmcSlot.hh:141
static const int isShort
Definition XrdRmcSlot.hh:145
static const int lenMask
Definition XrdRmcSlot.hh:144
int Push(XrdRmcSlot *Base, XrdRmcSlot *sP)
Definition XrdRmcSlot.hh:81
SlotList Own
Definition XrdRmcSlot.hh:140
~XrdRmcSlot()
Definition XrdRmcSlot.hh:152
SlotState Status
Definition XrdRmcSlot.hh:139
static void Init(XrdRmcSlot *Base, int Num)
Definition XrdRmcSlot.hh:63
int Pull(XrdRmcSlot *Base)
Definition XrdRmcSlot.hh:74
static const int inTrans
Definition XrdRmcSlot.hh:146
XrdRmcSlot()
Definition XrdRmcSlot.hh:150
void reRef(XrdRmcSlot *Base)
Definition XrdRmcSlot.hh:102
int Count
Definition XrdRmcSlot.hh:142
static int Find(XrdRmcSlot *Base, long long What, int n)
Definition XrdRmcSlot.hh:48
long long Contents
Definition XrdRmcSlot.hh:136
static const int isNew
Definition XrdRmcSlot.hh:148
XrdOucCacheIO * Key
Definition XrdRmcSlot.hh:137
void Hide(XrdRmcSlot *Base, int *hTab, int hI)
Definition XrdRmcSlot.hh:53
static const int isSUSE
Definition XrdRmcSlot.hh:147
void Owner(XrdRmcSlot *Base, XrdRmcSlot *sP)
Definition XrdRmcSlot.hh:96
Definition XrdSysPthread.hh:494
Definition XrdRmcSlot.hh:117
int Prev
Definition XrdRmcSlot.hh:119
int Next
Definition XrdRmcSlot.hh:118
Definition XrdRmcSlot.hh:123
XrdSysSemaphore * ioEnd
Definition XrdRmcSlot.hh:124
ioQ(ioQ *First, XrdSysSemaphore *ioW)
Definition XrdRmcSlot.hh:125
ioQ * Next
Definition XrdRmcSlot.hh:123
Definition XrdRmcSlot.hh:130
struct SlotList LRU
Definition XrdRmcSlot.hh:132
int inUse
Definition XrdRmcSlot.hh:133
XrdRmcData * Data
Definition XrdRmcSlot.hh:131
struct ioQ * waitQ
Definition XrdRmcSlot.hh:130