|
xrootd
|
00001 #ifndef __XRDOUCCACHESLOT_HH__ 00002 #define __XRDOUCCACHESLOT_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O u c C a c h e S l o t . h h */ 00006 /* */ 00007 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 /* This class is used to support a memory cache used by an XrdOucCache actual 00034 implementation. 00035 */ 00036 00037 class XrdOucCacheData; 00038 class XrdOucCacheIO; 00039 class XrdSysSemaphore; 00040 00041 class XrdOucCacheSlot 00042 { 00043 public: 00044 00045 inline void File(XrdOucCacheIO *kV, int you) 00046 {Status.Data = 0; Key = kV; HLink = you; Count = 1;} 00047 00048 static inline int Find(XrdOucCacheSlot *Base, long long What, int n) 00049 {while(n && Base[n].Contents != What) n=Base[n].HLink; 00050 return n; 00051 } 00052 00053 inline void Hide(XrdOucCacheSlot *Base, int *hTab, int hI) 00054 {int j, Slot = this-Base; 00055 if (hTab[hI] == Slot) hTab[hI] = HLink; 00056 else if ((j = hTab[hI])) 00057 {while((hI=Base[j].HLink) && hI != Slot) j=hI; 00058 if (hI) Base[j].HLink = Base[hI].HLink; 00059 } 00060 Count = 0; Contents = -1; 00061 } 00062 00063 static void Init(XrdOucCacheSlot *Base, int Num) 00064 {int i; 00065 Base->Status.LRU.Next = Base->Status.LRU.Prev = 0; 00066 Base->Own.Next = Base->Own.Prev = 0; 00067 for (i = 1; i < Num; i++) 00068 {Base[i].Status.LRU.Next = Base[i].Status.LRU.Prev = i; 00069 Base[i].Own.Next = Base[i].Own.Prev = i; 00070 Base->Push(Base, &Base[i]); 00071 } 00072 } 00073 00074 inline int Pull(XrdOucCacheSlot *Base) 00075 {Base[Status.LRU.Prev].Status.LRU.Next = Status.LRU.Next; 00076 Base[Status.LRU.Next].Status.LRU.Prev = Status.LRU.Prev; 00077 Status.LRU.Next = Status.LRU.Prev = this-Base; 00078 return Status.LRU.Next; 00079 } 00080 00081 inline int Push(XrdOucCacheSlot *Base, XrdOucCacheSlot *sP) 00082 {int UrNum = sP-Base, MyNum = this-Base; 00083 sP->Status.LRU.Next = MyNum; 00084 sP->Status.LRU.Prev = Status.LRU.Prev; 00085 Base[Status.LRU.Prev].Status.LRU.Next = UrNum; 00086 Status.LRU.Prev = UrNum; 00087 return UrNum; 00088 } 00089 00090 inline void Owner(XrdOucCacheSlot *Base) 00091 {Base[Own.Prev].Own.Next = Own.Next; 00092 Base[Own.Next].Own.Prev = Own.Prev; 00093 Own.Next = Own.Prev = this-Base; 00094 } 00095 00096 inline void Owner(XrdOucCacheSlot *Base, XrdOucCacheSlot *sP) 00097 {int UrNum = sP-Base, MyNum = this-Base; 00098 sP->Own.Next = MyNum; sP->Own.Prev = Own.Prev; 00099 Base[Own.Prev].Own.Next = UrNum; Own.Prev = UrNum; 00100 } 00101 00102 inline void reRef(XrdOucCacheSlot *Base) 00103 { Status.LRU.Prev = Base->Status.LRU.Prev; 00104 Base[ Status.LRU.Prev].Status.LRU.Next = this-Base; 00105 Base->Status.LRU.Prev = this-Base; 00106 Status.LRU.Next = 0; 00107 } 00108 00109 inline void unRef(XrdOucCacheSlot *Base) 00110 { Status.LRU.Next = Base->Status.LRU.Next; 00111 Base [Status.LRU.Next].Status.LRU.Prev = this-Base; 00112 Base->Status.LRU.Next = this-Base; 00113 Status.LRU.Prev = 0; 00114 } 00115 00116 struct SlotList 00117 { 00118 int Next; 00119 int Prev; 00120 }; 00121 00122 struct ioQ 00123 {ioQ *Next; 00124 XrdSysSemaphore *ioEnd; 00125 ioQ(ioQ *First, XrdSysSemaphore *ioW) 00126 : Next(First), ioEnd(ioW) {} 00127 }; 00128 00129 union SlotState 00130 {struct ioQ *waitQ; 00131 XrdOucCacheData *Data; 00132 struct SlotList LRU; 00133 int inUse; 00134 }; 00135 00136 union {long long Contents; 00137 XrdOucCacheIO *Key; 00138 }; 00139 SlotState Status; 00140 SlotList Own; 00141 int HLink; 00142 int Count; 00143 00144 static const int lenMask = 0x01ffffff; // Mask to get true value in Count 00145 static const int isShort = 0x80000000; // Short page, Count & lenMask == size 00146 static const int inTrans = 0x40000000; // Segment is in transit 00147 static const int isSUSE = 0x20000000; // Segment is single use 00148 static const int isNew = 0x10000000; // Segment is new (not yet referenced) 00149 00150 XrdOucCacheSlot() : Contents(-1), HLink(0), Count(0) {} 00151 00152 ~XrdOucCacheSlot() {} 00153 }; 00154 #endif
1.7.6.1