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 char AsyncMode;
00109 char isMMapped;
00110 char 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, int sfOK=0,
00123 struct stat *sP=0);
00124 ~XrdXrootdFile();
00125
00126 private:
00127 int bin2hex(char *outbuff, char *inbuff, int inlen);
00128 static XrdXrootdFileLock *Locker;
00129 static int sfOK;
00130 static const char *TraceID;
00131 };
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 #define XRD_FTABSIZE 16
00143
00144
00145
00146
00147
00148 class XrdXrootdFileTable
00149 {
00150 public:
00151
00152 int Add(XrdXrootdFile *fp);
00153
00154 XrdXrootdFile *Del(XrdXrootdMonitor *monP, int fnum, bool dodel=true);
00155
00156 inline XrdXrootdFile *Get(int fnum)
00157 {if (fnum >= 0)
00158 {if (fnum < XRD_FTABSIZE) return FTab[fnum];
00159 if (XTab && (fnum-XRD_FTABSIZE)<XTnum)
00160 return XTab[fnum-XRD_FTABSIZE];
00161 }
00162 return (XrdXrootdFile *)0;
00163 }
00164
00165 void Recycle(XrdXrootdMonitor *monP);
00166
00167 XrdXrootdFileTable(unsigned int mid=0) : fhProc(0), FTfree(0), monID(mid),
00168 XTab(0), XTnum(0), XTfree(0)
00169 {memset((void *)FTab, 0, sizeof(FTab));}
00170
00171 private:
00172
00173 ~XrdXrootdFileTable() {}
00174
00175 static const char *TraceID;
00176 static const char *ID;
00177 XrdXrootdFileHP *fhProc;
00178
00179 XrdXrootdFile *FTab[XRD_FTABSIZE];
00180 int FTfree;
00181 unsigned int monID;
00182
00183 XrdXrootdFile **XTab;
00184 int XTnum;
00185 int XTfree;
00186 };
00187 #endif