XRootD
XrdPosixObject.hh
Go to the documentation of this file.
1 #ifndef __XRDPOSIXOBJECT_HH__
2 #define __XRDPOSIXOBJECT_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d P o s i x O b j e c t . h h */
6 /* */
7 /* (c) 2013 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 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <sys/types.h>
34 
35 #include "XrdOuc/XrdOucECMsg.hh"
36 #include "XrdSys/XrdSysAtomics.hh"
37 #include "XrdSys/XrdSysPthread.hh"
38 
39 #include <mutex>
40 
41 class XrdPosixDir;
42 class XrdPosixFile;
43 
45 {
46 public:
47 
48  bool AssignFD(bool isStream=false);
49 
50 static bool CanStream() {return baseFD == 0 && freeFD < 255;}
51 
52 static XrdPosixDir *Dir (int fildes, bool glk=false);
53 
54 static XrdPosixFile *File(int fildes, bool glk=false);
55 
56  int FDNum() {return fdNum;}
57 
58  XrdOucECMsg getECMsg() const;
59 
60 static int Init(int numfd);
61 
62  void Lock(bool wr=true)
63  {if (wr) objMutex.WriteLock();
64  else objMutex.ReadLock();
65  }
66 
70  }
75  }
76 
77 static void Release(XrdPosixObject *oP, bool needlk=true);
78 
79 static XrdPosixDir *ReleaseDir( int fildes);
80 
81 static XrdPosixFile *ReleaseFile(int fildes);
82 
83 static void Shutdown();
84 
85  void UnLock() {objMutex.UnLock();}
86 
87 static bool Valid(int fd)
88  {return fd >= baseFD && fd <= (highFD+baseFD)
89  && myFiles && myFiles[fd-baseFD];}
90 
91 virtual bool Who(XrdPosixDir **dirP) {return false;}
92 
93 virtual bool Who(XrdPosixFile **fileP) {return false;}
94 
95  XrdPosixObject() : fdNum(-1),refCnt(0),ecMsg("[posix]") {}
96 virtual ~XrdPosixObject() {if (fdNum >= 0) Release(this);}
97 
98 protected:
101  int fdNum;
102  int refCnt;
103 
104 public:
105  mutable std::mutex ecMutex; // Mutex protecting concurrenct access to ecMsg.
106  XrdOucECMsg ecMsg; // Last error occurring on this file. Note multiple operations may be in flight; this may not correspond to the last operation your thread performed
107 
108 private:
109 
110 static XrdSysMutex fdMutex;
111 static XrdPosixObject **myFiles;
112 static int lastFD;
113 static int highFD;
114 static int baseFD;
115 static int freeFD;
116 static int posxFD;
117 static int devNull;
118 };
119 #endif
#define AtomicInc(x)
#define AtomicBeg(Mtx)
#define AtomicDec(x)
#define AtomicEnd(Mtx)
#define AtomicRet(mtx, x)
virtual bool Who(XrdPosixFile **fileP)
XrdSysRecMutex updMutex
static void Release(XrdPosixObject *oP, bool needlk=true)
static void Shutdown()
bool AssignFD(bool isStream=false)
static XrdPosixDir * Dir(int fildes, bool glk=false)
virtual ~XrdPosixObject()
std::mutex ecMutex
static XrdPosixDir * ReleaseDir(int fildes)
XrdSysRWLock objMutex
XrdOucECMsg getECMsg() const
static int Init(int numfd)
virtual bool Who(XrdPosixDir **dirP)
static XrdPosixFile * ReleaseFile(int fildes)
static bool Valid(int fd)
static bool CanStream()
XrdOucECMsg ecMsg
void Lock(bool wr=true)
static XrdPosixFile * File(int fildes, bool glk=false)