00001 #ifndef __XRDRMCSLOT_HH__
00002 #define __XRDRMCSLOT_HH__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 class XrdRmcData;
00038 class XrdOucCacheIO;
00039 class XrdSysSemaphore;
00040
00041 class XrdRmcSlot
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(XrdRmcSlot *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(XrdRmcSlot *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(XrdRmcSlot *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(XrdRmcSlot *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(XrdRmcSlot *Base, XrdRmcSlot *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(XrdRmcSlot *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(XrdRmcSlot *Base, XrdRmcSlot *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(XrdRmcSlot *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(XrdRmcSlot *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 XrdRmcData *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;
00145 static const int isShort = 0x80000000;
00146 static const int inTrans = 0x40000000;
00147 static const int isSUSE = 0x20000000;
00148 static const int isNew = 0x10000000;
00149
00150 XrdRmcSlot() : Contents(-1), HLink(0), Count(0) {}
00151
00152 ~XrdRmcSlot() {}
00153 };
00154 #endif