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