xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
37 class XrdRmcData;
38 class XrdOucCacheIO;
39 class XrdSysSemaphore;
40 
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(XrdRmcSlot *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(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 
63 static 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 
74 inline int Pull(XrdRmcSlot *Base)
77  Status.LRU.Next = Status.LRU.Prev = this-Base;
78  return Status.LRU.Next;
79  }
80 
81 inline int Push(XrdRmcSlot *Base, XrdRmcSlot *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(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 
96 inline 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 
102 inline 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 
109 inline 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 
116 struct SlotList
117  {
118  int Next;
119  int Prev;
120  };
121 
122 struct 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 
136 union {long long Contents;
138  };
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  XrdRmcSlot() : Contents(-1), HLink(0), Count(0) {}
151 
153 };
154 #endif
XrdRmcSlot()
Definition: XrdRmcSlot.hh:150
~XrdRmcSlot()
Definition: XrdRmcSlot.hh:152
Definition: XrdRmcSlot.hh:122
SlotState Status
Definition: XrdRmcSlot.hh:139
ioQ(ioQ *First, XrdSysSemaphore *ioW)
Definition: XrdRmcSlot.hh:125
struct SlotList LRU
Definition: XrdRmcSlot.hh:132
struct ioQ * waitQ
Definition: XrdRmcSlot.hh:130
Definition: XrdOucCache.hh:104
void Hide(XrdRmcSlot *Base, int *hTab, int hI)
Definition: XrdRmcSlot.hh:53
Definition: XrdRmcSlot.hh:41
long long Contents
Definition: XrdRmcSlot.hh:136
static int Find(XrdRmcSlot *Base, long long What, int n)
Definition: XrdRmcSlot.hh:48
Definition: XrdRmcSlot.hh:129
XrdSysSemaphore * ioEnd
Definition: XrdRmcSlot.hh:124
int inUse
Definition: XrdRmcSlot.hh:133
int Count
Definition: XrdRmcSlot.hh:142
int Pull(XrdRmcSlot *Base)
Definition: XrdRmcSlot.hh:74
static const int isShort
Definition: XrdRmcSlot.hh:145
Definition: XrdSysPthread.hh:493
int Next
Definition: XrdRmcSlot.hh:118
ioQ * Next
Definition: XrdRmcSlot.hh:123
SlotList Own
Definition: XrdRmcSlot.hh:140
int Prev
Definition: XrdRmcSlot.hh:119
XrdOucCacheIO * Key
Definition: XrdRmcSlot.hh:137
static const int isNew
Definition: XrdRmcSlot.hh:148
void reRef(XrdRmcSlot *Base)
Definition: XrdRmcSlot.hh:102
void Owner(XrdRmcSlot *Base, XrdRmcSlot *sP)
Definition: XrdRmcSlot.hh:96
void File(XrdOucCacheIO *kV, int you)
Definition: XrdRmcSlot.hh:45
Definition: XrdRmcData.hh:42
int HLink
Definition: XrdRmcSlot.hh:141
static const int inTrans
Definition: XrdRmcSlot.hh:146
XrdRmcData * Data
Definition: XrdRmcSlot.hh:131
static const int lenMask
Definition: XrdRmcSlot.hh:144
static const int isSUSE
Definition: XrdRmcSlot.hh:147
void unRef(XrdRmcSlot *Base)
Definition: XrdRmcSlot.hh:109
Definition: XrdRmcSlot.hh:116
void Owner(XrdRmcSlot *Base)
Definition: XrdRmcSlot.hh:90
int Push(XrdRmcSlot *Base, XrdRmcSlot *sP)
Definition: XrdRmcSlot.hh:81
static void Init(XrdRmcSlot *Base, int Num)
Definition: XrdRmcSlot.hh:63