xrootd
XrdOucCacheReal.hh
Go to the documentation of this file.
00001 #ifndef __XRDOUCCACHEREAL_HH__
00002 #define __XRDOUCCACHEREAL_HH__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                    X r d O u c C a c h e R e a l . 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 
00013 #include "XrdOuc/XrdOucCache.hh"
00014 #include "XrdOuc/XrdOucCacheSlot.hh"
00015 #include "XrdSys/XrdSysPthread.hh"
00016 
00017 /* This class defines an actual implementation of an XrdOucCache object. */
00018 
00019 class XrdOucCacheReal : public XrdOucCache
00020 {
00021 friend class XrdOucCacheData;
00022 public:
00023 
00024 XrdOucCacheIO *Attach(XrdOucCacheIO *ioP, int Options=0);
00025 
00026 int            isAttached() {int n;
00027                              CMutex.Lock(); n = Attached; CMutex.UnLock();
00028                              return n;
00029                             }
00030 
00031                XrdOucCacheReal(int     &rc,     // Success = 0; o/w !0
00032                                Parms   &Parms,  // Parameters
00033                XrdOucCacheIO::aprParms *aprP=0);
00034 
00035               ~XrdOucCacheReal();
00036 
00037 void           PreRead();
00038 
00039 private:
00040 
00041 void      eMsg(const char *Path, const char *What, long long xOff,
00042                int xLen, int ec);
00043 int       Detach(XrdOucCacheIO *ioP);
00044 char     *Get(XrdOucCacheIO *ioP, long long lAddr, int &rGot, int &bIO);
00045 
00046 int       ioAdd(XrdOucCacheIO *KeyVal, int &iNum);
00047 int       ioDel(XrdOucCacheIO *KeyVal, int &iNum);
00048 
00049 inline
00050 int       ioEnt(XrdOucCacheIO *kVal)
00051                {union {short sV[4]; XrdOucCacheIO *pV;} Key = {{0,0,0,0}};
00052                 Key.pV = kVal;
00053                 return ((Key.sV[0]^Key.sV[1]^Key.sV[2]^Key.sV[3])&0x7fff)%hMax;
00054                }
00055 inline
00056 int       ioLookup(int &pip, int hip, void *kval)
00057                   {pip = 0;
00058                    while(hip && kval != Slots[hip].Key)
00059                         {pip = hip; hip = Slots[hip].HLink;}
00060                    return hip;
00061                   }
00062 
00063 int       Ref(char *Addr, int rAmt, int sFlags=0);
00064 void      Trunc(XrdOucCacheIO *ioP, long long lAddr);
00065 void      Upd(char *Addr, int wAmt, int wOff);
00066 
00067 static const long long Shift = 48;
00068 static const long long Strip = 0x00000000ffffffffLL;  //
00069 static const long long MaxFO = 0x000007ffffffffffLL;  // Min 4K page -> 8TB-1
00070 
00071 XrdOucCacheIO::aprParms aprDefault; // Default automatic preread
00072 
00073 XrdSysMutex      CMutex;
00074 XrdOucCacheSlot *Slots;       // 1-to-1 slot to memory map
00075 int             *Slash;       // Slot hash table
00076 char            *Base;        // Base of memory cache
00077 long long        HNum;
00078 long long        SegCnt;
00079 long long        SegSize;
00080 long long        OffMask;     // SegSize - 1
00081 long long        SegShft;     // log2(SegSize)
00082 int              SegFull;     // SegSize to mark
00083 int              maxCache;    // Maximum read to cache
00084 int              maxFiles;    // Maximum number of files to support
00085 int              Options;
00086 
00087 // The following supports CacheIO object tracking
00088 //
00089 int             *hTab;        // -> Hash Table
00090 int              hMax;        // Number of entries in table
00091 int              sFree;       // Index of free file slot
00092 int              sBeg;        // Index of file slot array in slot table
00093 int              sEnd;        // Last index + 1
00094 
00095 // Various options
00096 //
00097 char             Dbg;         // Debug setting
00098 char             Lgs;         // Log statistics
00099 
00100 // This is the attach/detach control area
00101 //
00102 XrdSysSemaphore *AZero;
00103 int              Attached;
00104 
00105 // This is the pre-read control area
00106 //
00107 struct prTask
00108       {prTask          *Next;
00109        XrdOucCacheData *Data;
00110       };
00111 void             PreRead(XrdOucCacheReal::prTask *prReq);
00112 prTask          *prFirst;
00113 prTask          *prLast;
00114 XrdSysMutex      prMutex;
00115 XrdSysSemaphore  prReady;
00116 XrdSysSemaphore *prStop;
00117 int              prNum;
00118 };
00119 #endif