xrootd
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 
13 /* This class is used to support a memory cache used by an XrdOucCache actual
14  implementation.
15 */
16 
17 class XrdOucCacheData;
18 class XrdOucCacheIO;
19 class XrdSysSemaphore;
20 
22 {
23 public:
24 
25 inline void File(XrdOucCacheIO *kV, int you)
26  {Status.Data = 0; Key = kV; HLink = you; Count = 1;}
27 
28 static inline int Find(XrdOucCacheSlot *Base, long long What, int n)
29  {while(n && Base[n].Contents != What) n=Base[n].HLink;
30  return n;
31  }
32 
33 inline void Hide(XrdOucCacheSlot *Base, int *hTab, int hI)
34  {int j, Slot = this-Base;
35  if (hTab[hI] == Slot) hTab[hI] = HLink;
36  else if ((j = hTab[hI]))
37  {while((hI=Base[j].HLink) && hI != Slot) j=hI;
38  if (hI) Base[j].HLink = Base[hI].HLink;
39  }
40  Count = 0; Contents = -1;
41  }
42 
43 static void Init(XrdOucCacheSlot *Base, int Num)
44  {int i;
45  Base->Status.LRU.Next = Base->Status.LRU.Prev = 0;
46  Base->Own.Next = Base->Own.Prev = 0;
47  for (i = 1; i < Num; i++)
48  {Base[i].Status.LRU.Next = Base[i].Status.LRU.Prev = i;
49  Base[i].Own.Next = Base[i].Own.Prev = i;
50  Base->Push(Base, &Base[i]);
51  }
52  }
53 
54 inline int Pull(XrdOucCacheSlot *Base)
57  Status.LRU.Next = Status.LRU.Prev = this-Base;
58  return Status.LRU.Next;
59  }
60 
61 inline int Push(XrdOucCacheSlot *Base, XrdOucCacheSlot *sP)
62  {int UrNum = sP-Base, MyNum = this-Base;
63  sP->Status.LRU.Next = MyNum;
64  sP->Status.LRU.Prev = Status.LRU.Prev;
65  Base[Status.LRU.Prev].Status.LRU.Next = UrNum;
66  Status.LRU.Prev = UrNum;
67  return UrNum;
68  }
69 
70 inline void Owner(XrdOucCacheSlot *Base)
71  {Base[Own.Prev].Own.Next = Own.Next;
72  Base[Own.Next].Own.Prev = Own.Prev;
73  Own.Next = Own.Prev = this-Base;
74  }
75 
76 inline void Owner(XrdOucCacheSlot *Base, XrdOucCacheSlot *sP)
77  {int UrNum = sP-Base, MyNum = this-Base;
78  sP->Own.Next = MyNum; sP->Own.Prev = Own.Prev;
79  Base[Own.Prev].Own.Next = UrNum; Own.Prev = UrNum;
80  }
81 
82 inline void reRef(XrdOucCacheSlot *Base)
83  { Status.LRU.Prev = Base->Status.LRU.Prev;
84  Base[ Status.LRU.Prev].Status.LRU.Next = this-Base;
85  Base->Status.LRU.Prev = this-Base;
86  Status.LRU.Next = 0;
87  }
88 
89 inline void unRef(XrdOucCacheSlot *Base)
90  { Status.LRU.Next = Base->Status.LRU.Next;
91  Base [Status.LRU.Next].Status.LRU.Prev = this-Base;
92  Base->Status.LRU.Next = this-Base;
93  Status.LRU.Prev = 0;
94  }
95 
96 struct SlotList
97  {
98  int Next;
99  int Prev;
100  };
101 
102 struct ioQ
105  ioQ(ioQ *First, XrdSysSemaphore *ioW)
106  : Next(First), ioEnd(ioW) {}
107  };
108 
110  {struct ioQ *waitQ;
112  struct SlotList LRU;
113  int inUse;
114  };
115 
116 union {long long Contents;
118  };
121 int HLink;
122 int Count;
123 
124 static const int lenMask = 0x01ffffff; // Mask to get true value in Count
125 static const int isShort = 0x80000000; // Short page, Count & lenMask == size
126 static const int inTrans = 0x40000000; // Segment is in transit
127 static const int isSUSE = 0x20000000; // Segment is single use
128 static const int isNew = 0x10000000; // Segment is new (not yet referenced)
129 
130  XrdOucCacheSlot() : Contents(-1), HLink(0), Count(0) {}
131 
133 };
134 #endif