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