Loading...
Searching...
No Matches
XrdPosixObject.hh
Go to the documentation of this file.
#ifndef __XRDPOSIXOBJECT_HH__
#define __XRDPOSIXOBJECT_HH__
/******************************************************************************/
/* */
/* X r d P o s i x O b j e c t . h h */
/* */
/* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <sys/types.h>
#include "XrdOuc/XrdOucECMsg.hh"
#include "XrdSys/XrdSysAtomics.hh"
#include "XrdSys/XrdSysPthread.hh"
class XrdPosixDir;
class XrdPosixFile;
class XrdPosixObject
{
public:
bool AssignFD(bool isStream=false);
static bool CanStream() {return baseFD == 0 && freeFD < 255;}
static XrdPosixDir *Dir (int fildes, bool glk=false);
static XrdPosixFile *File(int fildes, bool glk=false);
int FDNum() {return fdNum;}
XrdOucECMsg* getECMsg() {return &ecMsg;}
static int Init(int numfd);
void Lock(bool wr=true)
{if (wr) objMutex.WriteLock();
else objMutex.ReadLock();
}
void Ref() {AtomicBeg(updMutex);
AtomicInc(refCnt);
AtomicEnd(updMutex);
}
int Refs() {AtomicRet(updMutex, refCnt);}
void unRef() {AtomicBeg(updMutex);
AtomicDec(refCnt);
AtomicEnd(updMutex);
}
static void Release(XrdPosixObject *oP, bool needlk=true);
static XrdPosixDir *ReleaseDir( int fildes);
static XrdPosixFile *ReleaseFile(int fildes);
static void Shutdown();
void UnLock() {objMutex.UnLock();}
static bool Valid(int fd)
{return fd >= baseFD && fd <= (highFD+baseFD)
&& myFiles && myFiles[fd-baseFD];}
virtual bool Who(XrdPosixDir **dirP) {return false;}
virtual bool Who(XrdPosixFile **fileP) {return false;}
XrdPosixObject() : ecMsg("[posix]"),fdNum(-1),refCnt(0) {}
virtual ~XrdPosixObject() {if (fdNum >= 0) Release(this);}
XrdOucECMsg ecMsg;
protected:
XrdSysRecMutex updMutex;
XrdSysRWLock objMutex;
int fdNum;
int refCnt;
private:
static XrdSysMutex fdMutex;
static XrdPosixObject **myFiles;
static int lastFD;
static int highFD;
static int baseFD;
static int freeFD;
static int posxFD;
static int devNull;
};
#endif
XrdOucECMsg.hh
Dir
XrdOucString Dir
Definition XrdSecpwdSrvAdmin.cc:161
File
XrdOucString File
Definition XrdSecpwdSrvAdmin.cc:159
XrdSysAtomics.hh
AtomicInc
#define AtomicInc(x)
Definition XrdSysAtomics.hh:72
AtomicBeg
#define AtomicBeg(Mtx)
Definition XrdSysAtomics.hh:63
AtomicDec
#define AtomicDec(x)
Definition XrdSysAtomics.hh:68
AtomicEnd
#define AtomicEnd(Mtx)
Definition XrdSysAtomics.hh:64
AtomicRet
#define AtomicRet(mtx, x)
Definition XrdSysAtomics.hh:76
XrdSysPthread.hh
XrdOucECMsg
Definition XrdOucECMsg.hh:39
XrdPosixDir
Definition XrdPosixDir.hh:52
XrdPosixFile
Definition XrdPosixFile.hh:62
XrdPosixObject
Definition XrdPosixObject.hh:43
XrdPosixObject::Ref
void Ref()
Definition XrdPosixObject.hh:65
XrdPosixObject::Who
virtual bool Who(XrdPosixFile **fileP)
Definition XrdPosixObject.hh:91
XrdPosixObject::unRef
void unRef()
Definition XrdPosixObject.hh:70
XrdPosixObject::updMutex
XrdSysRecMutex updMutex
Definition XrdPosixObject.hh:99
XrdPosixObject::Release
static void Release(XrdPosixObject *oP, bool needlk=true)
Definition XrdPosixObject.cc:254
XrdPosixObject::Shutdown
static void Shutdown()
Definition XrdPosixObject.cc:317
XrdPosixObject::AssignFD
bool AssignFD(bool isStream=false)
Definition XrdPosixObject.cc:67
XrdPosixObject::FDNum
int FDNum()
Definition XrdPosixObject.hh:54
XrdPosixObject::~XrdPosixObject
virtual ~XrdPosixObject()
Definition XrdPosixObject.hh:94
XrdPosixObject::XrdPosixObject
XrdPosixObject()
Definition XrdPosixObject.hh:93
XrdPosixObject::refCnt
int refCnt
Definition XrdPosixObject.hh:102
XrdPosixObject::ReleaseDir
static XrdPosixDir * ReleaseDir(int fildes)
Definition XrdPosixObject.cc:281
XrdPosixObject::objMutex
XrdSysRWLock objMutex
Definition XrdPosixObject.hh:100
XrdPosixObject::Init
static int Init(int numfd)
Definition XrdPosixObject.cc:206
XrdPosixObject::Who
virtual bool Who(XrdPosixDir **dirP)
Definition XrdPosixObject.hh:89
XrdPosixObject::ReleaseFile
static XrdPosixFile * ReleaseFile(int fildes)
Definition XrdPosixObject.cc:299
XrdPosixObject::Refs
int Refs()
Definition XrdPosixObject.hh:69
XrdPosixObject::Valid
static bool Valid(int fd)
Definition XrdPosixObject.hh:85
XrdPosixObject::CanStream
static bool CanStream()
Definition XrdPosixObject.hh:48
XrdPosixObject::fdNum
int fdNum
Definition XrdPosixObject.hh:101
XrdPosixObject::UnLock
void UnLock()
Definition XrdPosixObject.hh:83
XrdPosixObject::ecMsg
XrdOucECMsg ecMsg
Definition XrdPosixObject.hh:96
XrdPosixObject::getECMsg
XrdOucECMsg * getECMsg()
Definition XrdPosixObject.hh:56
XrdPosixObject::Lock
void Lock(bool wr=true)
Definition XrdPosixObject.hh:60
XrdSysMutex
Definition XrdSysPthread.hh:165
XrdSysRWLock
Definition XrdSysPthread.hh:330
XrdSysRecMutex
Definition XrdSysPthread.hh:242