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 "XrdSys/XrdSysAtomics.hh"
36 #include "XrdSys/XrdSysPthread.hh"
37 
38 class XrdPosixDir;
39 class XrdPosixFile;
40 
42 {
43 public:
44 
45  bool AssignFD(bool isStream=false);
46 
47 static bool CanStream() {return baseFD == 0 && freeFD < 255;}
48 
49 static XrdPosixDir *Dir (int fildes, bool glk=false);
50 
51 static XrdPosixFile *File(int fildes, bool glk=false);
52 
53  int FDNum() {return fdNum;}
54 
55 static int Init(int numfd);
56 
57  void Lock(bool wr=true)
58  {if (wr) objMutex.WriteLock();
59  else objMutex.ReadLock();
60  }
61 
65  }
70  }
71 
72 static void Release(XrdPosixObject *oP, bool needlk=true);
73 
74 static XrdPosixDir *ReleaseDir( int fildes);
75 
76 static XrdPosixFile *ReleaseFile(int fildes);
77 
78 static void Shutdown();
79 
80  void UnLock() {objMutex.UnLock();}
81 
82 static bool Valid(int fd)
83  {return fd >= baseFD && fd <= (highFD+baseFD)
84  && myFiles && myFiles[fd-baseFD];}
85 
86 virtual bool Who(XrdPosixDir **dirP) {return false;}
87 
88 virtual bool Who(XrdPosixFile **fileP) {return false;}
89 
90  XrdPosixObject() : fdNum(-1), refCnt(0) {}
91 virtual ~XrdPosixObject() {if (fdNum >= 0) Release(this);}
92 
93 protected:
96  int fdNum;
97  int refCnt;
98 
99 private:
100 
103 static int lastFD;
104 static int highFD;
105 static int baseFD;
106 static int freeFD;
107 static int posxFD;
108 static int devNull;
109 };
110 #endif
#define AtomicInc(x)
Definition: XrdSysAtomics.hh:72
XrdSysRecMutex updMutex
Definition: XrdPosixObject.hh:94
Definition: XrdSysPthread.hh:241
Definition: XrdPosixDir.hh:48
virtual bool Who(XrdPosixDir **dirP)
Definition: XrdPosixObject.hh:86
Definition: XrdPosixFile.hh:57
Definition: XrdSysPthread.hh:297
int refCnt
Definition: XrdPosixObject.hh:97
static XrdPosixDir * Dir(int fildes, bool glk=false)
int Refs()
Definition: XrdPosixObject.hh:66
static int Init(int numfd)
Definition: XrdPosixObject.hh:41
void Ref()
Definition: XrdPosixObject.hh:62
static XrdPosixFile * ReleaseFile(int fildes)
XrdPosixObject()
Definition: XrdPosixObject.hh:90
void UnLock()
Definition: XrdPosixObject.hh:80
XrdSysRWLock objMutex
Definition: XrdPosixObject.hh:95
void ReadLock()
Definition: XrdSysPthread.hh:310
virtual bool Who(XrdPosixFile **fileP)
Definition: XrdPosixObject.hh:88
static XrdPosixDir * ReleaseDir(int fildes)
#define AtomicBeg(Mtx)
Definition: XrdSysAtomics.hh:63
#define AtomicDec(x)
Definition: XrdSysAtomics.hh:68
Definition: XrdSysPthread.hh:165
void WriteLock()
Definition: XrdSysPthread.hh:311
#define AtomicEnd(Mtx)
Definition: XrdSysAtomics.hh:64
void Lock(bool wr=true)
Definition: XrdPosixObject.hh:57
static void Release(XrdPosixObject *oP, bool needlk=true)
static int highFD
Definition: XrdPosixObject.hh:104
virtual ~XrdPosixObject()
Definition: XrdPosixObject.hh:91
static XrdSysMutex fdMutex
Definition: XrdPosixObject.hh:101
#define AtomicRet(mtx, x)
Definition: XrdSysAtomics.hh:76
static int devNull
Definition: XrdPosixObject.hh:108
static int posxFD
Definition: XrdPosixObject.hh:107
static bool Valid(int fd)
Definition: XrdPosixObject.hh:82
static bool CanStream()
Definition: XrdPosixObject.hh:47
static XrdPosixObject ** myFiles
Definition: XrdPosixObject.hh:102
static int freeFD
Definition: XrdPosixObject.hh:106
static int baseFD
Definition: XrdPosixObject.hh:105
int fdNum
Definition: XrdPosixObject.hh:96
bool AssignFD(bool isStream=false)
static void Shutdown()
static int lastFD
Definition: XrdPosixObject.hh:103
static XrdPosixFile * File(int fildes, bool glk=false)
void UnLock()
Definition: XrdSysPthread.hh:316
void unRef()
Definition: XrdPosixObject.hh:67
int FDNum()
Definition: XrdPosixObject.hh:53