xrootd
XrdOucCacheReal.hh
Go to the documentation of this file.
1 #ifndef __XRDOUCCACHEREAL_HH__
2 #define __XRDOUCCACHEREAL_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c C a c h e R e a l . 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 
15 #include "XrdSys/XrdSysPthread.hh"
16 
17 /* This class defines an actual implementation of an XrdOucCache object. */
18 
20 {
21 friend class XrdOucCacheData;
22 public:
23 
25 
26 int isAttached() {int n;
27  CMutex.Lock(); n = Attached; CMutex.UnLock();
28  return n;
29  }
30 
31  XrdOucCacheReal(int &rc, // Success = 0; o/w !0
32  Parms &Parms, // Parameters
33  XrdOucCacheIO::aprParms *aprP=0);
34 
36 
37 void PreRead();
38 
39 private:
40 
41 void eMsg(const char *Path, const char *What, long long xOff,
42  int xLen, int ec);
43 int Detach(XrdOucCacheIO *ioP);
44 char *Get(XrdOucCacheIO *ioP, long long lAddr, int &rGot, int &bIO);
45 
46 int ioAdd(XrdOucCacheIO *KeyVal, int &iNum);
47 int ioDel(XrdOucCacheIO *KeyVal, int &iNum);
48 
49 inline
50 int ioEnt(XrdOucCacheIO *kVal)
51  {union {short sV[4]; XrdOucCacheIO *pV;} Key = {{0,0,0,0}};
52  Key.pV = kVal;
53  return ((Key.sV[0]^Key.sV[1]^Key.sV[2]^Key.sV[3])&0x7fff)%hMax;
54  }
55 inline
56 int ioLookup(int &pip, int hip, void *kval)
57  {pip = 0;
58  while(hip && kval != Slots[hip].Key)
59  {pip = hip; hip = Slots[hip].HLink;}
60  return hip;
61  }
62 
63 int Ref(char *Addr, int rAmt, int sFlags=0);
64 void Trunc(XrdOucCacheIO *ioP, long long lAddr);
65 void Upd(char *Addr, int wAmt, int wOff);
66 
67 static const long long Shift = 48;
68 static const long long Strip = 0x00000000ffffffffLL; //
69 static const long long MaxFO = 0x000007ffffffffffLL; // Min 4K page -> 8TB-1
70 
71 XrdOucCacheIO::aprParms aprDefault; // Default automatic preread
72 
74 XrdOucCacheSlot *Slots; // 1-to-1 slot to memory map
75 int *Slash; // Slot hash table
76 char *Base; // Base of memory cache
77 long long HNum;
78 long long SegCnt;
79 long long SegSize;
80 long long OffMask; // SegSize - 1
81 long long SegShft; // log2(SegSize)
82 int SegFull; // SegSize to mark
83 int maxCache; // Maximum read to cache
84 int maxFiles; // Maximum number of files to support
85 int Options;
86 
87 // The following supports CacheIO object tracking
88 //
89 int *hTab; // -> Hash Table
90 int hMax; // Number of entries in table
91 int sFree; // Index of free file slot
92 int sBeg; // Index of file slot array in slot table
93 int sEnd; // Last index + 1
94 
95 // Various options
96 //
97 char Dbg; // Debug setting
98 char Lgs; // Log statistics
99 
100 // This is the attach/detach control area
101 //
104 
105 // This is the pre-read control area
106 //
107 struct prTask
110  };
111 void PreRead(XrdOucCacheReal::prTask *prReq);
117 int prNum;
118 };
119 #endif