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 class XrdPosixDir;
40 class XrdPosixFile;
41 
43 {
44 public:
45 
46  bool AssignFD(bool isStream=false);
47 
48 static bool CanStream() {return baseFD == 0 && freeFD < 255;}
49 
50 static XrdPosixDir *Dir (int fildes, bool glk=false);
51 
52 static XrdPosixFile *File(int fildes, bool glk=false);
53 
54  int FDNum() {return fdNum;}
55 
56  XrdOucECMsg* getECMsg() {return &ecMsg;}
57 
58 static int Init(int numfd);
59 
60  void Lock(bool wr=true)
61  {if (wr) objMutex.WriteLock();
62  else objMutex.ReadLock();
63  }
64 
68  }
73  }
74 
75 static void Release(XrdPosixObject *oP, bool needlk=true);
76 
77 static XrdPosixDir *ReleaseDir( int fildes);
78 
79 static XrdPosixFile *ReleaseFile(int fildes);
80 
81 static void Shutdown();
82 
83  void UnLock() {objMutex.UnLock();}
84 
85 static bool Valid(int fd)
86  {return fd >= baseFD && fd <= (highFD+baseFD)
87  && myFiles && myFiles[fd-baseFD];}
88 
89 virtual bool Who(XrdPosixDir **dirP) {return false;}
90 
91 virtual bool Who(XrdPosixFile **fileP) {return false;}
92 
93  XrdPosixObject() : ecMsg("[posix]"),fdNum(-1),refCnt(0) {}
94 virtual ~XrdPosixObject() {if (fdNum >= 0) Release(this);}
95 
97 
98 protected:
101  int fdNum;
102  int refCnt;
103 
104 private:
105 
106 static XrdSysMutex fdMutex;
107 static XrdPosixObject **myFiles;
108 static int lastFD;
109 static int highFD;
110 static int baseFD;
111 static int freeFD;
112 static int posxFD;
113 static int devNull;
114 };
115 #endif
#define AtomicInc(x)
#define AtomicBeg(Mtx)
#define AtomicDec(x)
#define AtomicEnd(Mtx)
#define AtomicRet(mtx, x)
XrdOucECMsg * getECMsg()
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()
static XrdPosixDir * ReleaseDir(int fildes)
XrdSysRWLock objMutex
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)