00001 #ifndef __XRDOUCCACHEREAL_HH__
00002 #define __XRDOUCCACHEREAL_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 #include "XrdOuc/XrdOucCacheDram.hh"
00034 #include "XrdOuc/XrdOucCacheSlot.hh"
00035 #include "XrdSys/XrdSysPthread.hh"
00036
00037
00038
00039 class XrdOucCacheReal : public XrdOucCacheDram
00040 {
00041 friend class XrdOucCacheData;
00042 public:
00043
00044 XrdOucCacheIO *Attach(XrdOucCacheIO *ioP, int Options=0);
00045
00046 int isAttached() {int n;
00047 CMutex.Lock(); n = Attached; CMutex.UnLock();
00048 return n;
00049 }
00050
00051 XrdOucCacheReal(int &rc,
00052 Parms &Parms,
00053 XrdOucCacheIO::aprParms *aprP=0);
00054
00055 ~XrdOucCacheReal();
00056
00057 void PreRead();
00058
00059 private:
00060
00061 void eMsg(const char *Path, const char *What, long long xOff,
00062 int xLen, int ec);
00063 int Detach(XrdOucCacheIO *ioP);
00064 char *Get(XrdOucCacheIO *ioP, long long lAddr, int &rGot, int &bIO);
00065
00066 int ioAdd(XrdOucCacheIO *KeyVal, int &iNum);
00067 int ioDel(XrdOucCacheIO *KeyVal, int &iNum);
00068
00069 inline
00070 int ioEnt(XrdOucCacheIO *kVal)
00071 {union {short sV[4]; XrdOucCacheIO *pV;} Key = {{0,0,0,0}};
00072 Key.pV = kVal;
00073 return ((Key.sV[0]^Key.sV[1]^Key.sV[2]^Key.sV[3])&0x7fff)%hMax;
00074 }
00075 inline
00076 int ioLookup(int &pip, int hip, void *kval)
00077 {pip = 0;
00078 while(hip && kval != Slots[hip].Key)
00079 {pip = hip; hip = Slots[hip].HLink;}
00080 return hip;
00081 }
00082
00083 int Ref(char *Addr, int rAmt, int sFlags=0);
00084 void Trunc(XrdOucCacheIO *ioP, long long lAddr);
00085 void Upd(char *Addr, int wAmt, int wOff);
00086
00087 static const long long Shift = 48;
00088 static const long long Strip = 0x00000000ffffffffLL;
00089 static const long long MaxFO = 0x000007ffffffffffLL;
00090
00091 XrdOucCacheIO::aprParms aprDefault;
00092
00093 XrdSysMutex CMutex;
00094 XrdOucCacheSlot *Slots;
00095 int *Slash;
00096 char *Base;
00097 long long HNum;
00098 long long SegCnt;
00099 long long SegSize;
00100 long long OffMask;
00101 long long SegShft;
00102 int SegFull;
00103 int maxCache;
00104 int maxFiles;
00105 int Options;
00106
00107
00108
00109 int *hTab;
00110 int hMax;
00111 int sFree;
00112 int sBeg;
00113 int sEnd;
00114
00115
00116
00117 char Dbg;
00118 char Lgs;
00119
00120
00121
00122 XrdSysSemaphore *AZero;
00123 int Attached;
00124
00125
00126
00127 struct prTask
00128 {prTask *Next;
00129 XrdOucCacheData *Data;
00130 };
00131 void PreRead(XrdOucCacheReal::prTask *prReq);
00132 prTask *prFirst;
00133 prTask *prLast;
00134 XrdSysMutex prMutex;
00135 XrdSysSemaphore prReady;
00136 XrdSysSemaphore *prStop;
00137 int prNum;
00138 };
00139 #endif