00001 #ifndef _XROOTD_FILE_H_
00002 #define _XROOTD_FILE_H_
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 #include <string.h>
00033 #include <vector>
00034
00035 #include "XProtocol/XPtypes.hh"
00036 #include "XrdSys/XrdSysPthread.hh"
00037 #include "XrdXrootd/XrdXrootdFileStats.hh"
00038
00039
00040
00041
00042
00043 class XrdXrootdFileHP
00044 {
00045 public:
00046
00047 void Avail(int fHandle) {fhMutex.Lock();
00048 bool done = (1 == refs--);
00049 if (noMore)
00050 {fhMutex.UnLock();
00051 if (done) delete this;
00052 } else {
00053 fhAvail.push_back(fHandle);
00054 fhMutex.UnLock();
00055 }
00056 }
00057
00058 void Delete() {fhMutex.Lock();
00059 if (!refs) {fhMutex.UnLock(); delete this;}
00060 else {noMore = true; fhMutex.UnLock();}
00061 }
00062
00063 int Get() {int fh;
00064 fhMutex.Lock();
00065 if (fhAvail.empty()) fh = -1;
00066 else {fh = fhAvail.back();
00067 fhAvail.pop_back();
00068 }
00069 fhMutex.UnLock();
00070 return fh;
00071 }
00072
00073 void Ref() {fhMutex.Lock(); refs++; fhMutex.UnLock();}
00074
00075 XrdXrootdFileHP(int rsv=2) : refs(1), noMore(false)
00076 {fhAvail.reserve(rsv);}
00077
00078 private:
00079
00080 ~XrdXrootdFileHP() {}
00081
00082 XrdSysMutex fhMutex;
00083 std::vector<int> fhAvail;
00084 int refs;
00085 bool noMore;
00086 };
00087
00088
00089
00090
00091
00092
00093 class XrdSfsFile;
00094 class XrdXrootdFileLock;
00095 class XrdXrootdMonitor;
00096
00097 class XrdXrootdFile
00098 {
00099 public:
00100
00101 XrdSfsFile *XrdSfsp;
00102 union {char *mmAddr;
00103 unsigned
00104 long long cbArg;
00105 };
00106 char *FileKey;
00107 char FileMode;
00108 bool AsyncMode;
00109 bool isMMapped;
00110 bool sfEnabled;
00111 union {int fdNum;
00112 int fHandle;
00113 };
00114 XrdXrootdFileHP *fhProc;
00115 const char *ID;
00116
00117 XrdXrootdFileStats Stats;
00118
00119 static void Init(XrdXrootdFileLock *lp, XrdSysError *erP, int sfok);
00120
00121 XrdXrootdFile(const char *id, const char *path, XrdSfsFile *fp,
00122 char mode='r', bool async=false, struct stat *sP=0);
00123 ~XrdXrootdFile();
00124
00125 private:
00126 int bin2hex(char *outbuff, char *inbuff, int inlen);
00127 static XrdXrootdFileLock *Locker;
00128 static int sfOK;
00129 static const char *TraceID;
00130 };
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 #define XRD_FTABSIZE 16
00142
00143
00144
00145
00146
00147 class XrdXrootdFileTable
00148 {
00149 public:
00150
00151 int Add(XrdXrootdFile *fp);
00152
00153 XrdXrootdFile *Del(XrdXrootdMonitor *monP, int fnum, bool dodel=true);
00154
00155 inline XrdXrootdFile *Get(int fnum)
00156 {if (fnum >= 0)
00157 {if (fnum < XRD_FTABSIZE) return FTab[fnum];
00158 if (XTab && (fnum-XRD_FTABSIZE)<XTnum)
00159 return XTab[fnum-XRD_FTABSIZE];
00160 }
00161 return (XrdXrootdFile *)0;
00162 }
00163
00164 void Recycle(XrdXrootdMonitor *monP);
00165
00166 XrdXrootdFileTable(unsigned int mid=0) : fhProc(0), FTfree(0), monID(mid),
00167 XTab(0), XTnum(0), XTfree(0)
00168 {memset((void *)FTab, 0, sizeof(FTab));}
00169
00170 private:
00171
00172 ~XrdXrootdFileTable() {}
00173
00174 static const char *TraceID;
00175 static const char *ID;
00176 XrdXrootdFileHP *fhProc;
00177
00178 XrdXrootdFile *FTab[XRD_FTABSIZE];
00179 int FTfree;
00180 unsigned int monID;
00181
00182 XrdXrootdFile **XTab;
00183 int XTnum;
00184 int XTfree;
00185 };
00186 #endif