Loading...
Searching...
No Matches
XrdSutPFCache.hh
Go to the documentation of this file.
#ifndef __SUT_CACHE_H__
#define __SUT_CACHE_H__
/******************************************************************************/
/* */
/* X r d S u t C a c h e . h h */
/* */
/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
/* Produced by Gerri Ganis for CERN */
/* */
/* 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 "XProtocol/XPtypes.hh"
#include "XrdSut/XrdSutPFEntry.hh"
#include "XrdOuc/XrdOucHash.hh"
#include "XrdOuc/XrdOucString.hh"
#include "XrdSys/XrdSysPthread.hh"
/******************************************************************************/
/* */
/* For caching temporary information during the authentication handshake */
/* */
/******************************************************************************/
class XrdSutPFCacheRef
{
public:
inline void Lock(XrdSysMutex *Mutex)
{if (mtx) {if (mtx != Mutex) mtx->UnLock();
else return;
}
Mutex->Lock();
mtx = Mutex;
};
inline void Set(XrdSysMutex *Mutex)
{if (mtx) {if (mtx != Mutex) mtx->UnLock();
else return;
}
mtx = Mutex;
};
inline void UnLock() {if (mtx) {mtx->UnLock(); mtx = 0;}}
XrdSutPFCacheRef() : mtx(0) {}
~XrdSutPFCacheRef() {if (mtx) UnLock();}
protected:
XrdSysMutex *mtx;
};
class XrdSutPFCache
{
private:
XrdSysRWLock rwlock; // Access synchronizator
int cachesz; // Number of entries allocated
int cachemx; // Largest Index of allocated entries
XrdSutPFEntry **cachent; // Pointers to filled entries
kXR_int32 utime; // time at which was last updated
int lifetime; // lifetime (in secs) of the cache info
XrdOucHash<kXR_int32> hashtable; // Reflects the file index structure
kXR_int32 htmtime; // time at which hash table was last rebuild
XrdOucString pfile; // file name (if loaded from file)
bool isinit; // true if already initialized
XrdSutPFEntry *Get(const char *ID, bool *wild);
bool Delete(XrdSutPFEntry *pfEnt);
static const int maxTries = 100; // Max time to try getting a lock
static const int retryMSW = 300; // Milliseconds to wait to get lock
public:
XrdSutPFCache() { cachemx = -1; cachesz = 0; cachent = 0; lifetime = 300;
utime = -1; htmtime = -1; pfile = ""; isinit = 0; }
virtual ~XrdSutPFCache();
// Status
int Entries() const { return (cachemx+1); }
bool Empty() const { return (cachemx == -1); }
// Initialization methods
int Init(int capacity = 100, bool lock = 1);
int Reset(int newsz = -1, bool lock = 1);
int Load(const char *pfname); // build cache of a pwd file
int Flush(const char *pfname = 0); // flush content to pwd file
int Refresh(); // refresh content from source file
int Rehash(bool force = 0, bool lock = 1); // (re)build hash table
void SetLifetime(int lifet = 300) { lifetime = lifet; }
// Cache management
XrdSutPFEntry *Get(int i) const { return (i<=cachemx) ? cachent[i] :
(XrdSutPFEntry *)0; }
XrdSutPFEntry *Get(XrdSutPFCacheRef &urRef, const char *ID, bool *wild = 0);
XrdSutPFEntry *Add(XrdSutPFCacheRef &urRef, const char *ID, bool force = 0);
bool Remove(const char *ID, int opt = 1);
int Trim(int lifet = 0);
// For debug purposes
void Dump(const char *msg= 0);
};
#endif
XPtypes.hh
kXR_int32
int kXR_int32
Definition XPtypes.hh:89
XrdOucHash.hh
XrdOucString.hh
XrdSutPFEntry.hh
XrdSysPthread.hh
ID
#define ID
Definition XrdXrootdAioBuff.cc:38
XrdOucHash
Definition XrdOucHash.hh:128
XrdOucString
Definition XrdOucString.hh:252
XrdSutPFCacheRef
Definition XrdSutPFCache.hh:44
XrdSutPFCacheRef::Lock
void Lock(XrdSysMutex *Mutex)
Definition XrdSutPFCache.hh:47
XrdSutPFCacheRef::~XrdSutPFCacheRef
~XrdSutPFCacheRef()
Definition XrdSutPFCache.hh:66
XrdSutPFCacheRef::mtx
XrdSysMutex * mtx
Definition XrdSutPFCache.hh:68
XrdSutPFCacheRef::Set
void Set(XrdSysMutex *Mutex)
Definition XrdSutPFCache.hh:55
XrdSutPFCacheRef::UnLock
void UnLock()
Definition XrdSutPFCache.hh:62
XrdSutPFCacheRef::XrdSutPFCacheRef
XrdSutPFCacheRef()
Definition XrdSutPFCache.hh:64
XrdSutPFCache::~XrdSutPFCache
virtual ~XrdSutPFCache()
Definition XrdSutPFCache.cc:49
XrdSutPFCache::Remove
bool Remove(const char *ID, int opt=1)
Definition XrdSutPFCache.cc:294
XrdSutPFCache::Empty
bool Empty() const
Definition XrdSutPFCache.hh:98
XrdSutPFCache::XrdSutPFCache
XrdSutPFCache()
Definition XrdSutPFCache.hh:92
XrdSutPFCache::Refresh
int Refresh()
Definition XrdSutPFCache.cc:769
XrdSutPFCache::Entries
int Entries() const
Definition XrdSutPFCache.hh:97
XrdSutPFCache::Flush
int Flush(const char *pfname=0)
Definition XrdSutPFCache.cc:701
XrdSutPFCache::Add
XrdSutPFEntry * Add(XrdSutPFCacheRef &urRef, const char *ID, bool force=0)
Definition XrdSutPFCache.cc:207
XrdSutPFCache::Get
XrdSutPFEntry * Get(int i) const
Definition XrdSutPFCache.hh:110
XrdSutPFCache::SetLifetime
void SetLifetime(int lifet=300)
Definition XrdSutPFCache.hh:107
XrdSutPFCache::Reset
int Reset(int newsz=-1, bool lock=1)
Definition XrdSutPFCache.cc:448
XrdSutPFCache::Init
int Init(int capacity=100, bool lock=1)
Definition XrdSutPFCache.cc:73
XrdSutPFCache::Dump
void Dump(const char *msg=0)
Definition XrdSutPFCache.cc:487
XrdSutPFCache::Load
int Load(const char *pfname)
Definition XrdSutPFCache.cc:531
XrdSutPFCache::Rehash
int Rehash(bool force=0, bool lock=1)
Definition XrdSutPFCache.cc:659
XrdSutPFCache::Trim
int Trim(int lifet=0)
Definition XrdSutPFCache.cc:410
XrdSutPFEntry
Definition XrdSutPFEntry.hh:78
XrdSysMutex
Definition XrdSysPthread.hh:165
XrdSysMutex::Lock
void Lock()
Definition XrdSysPthread.hh:222
XrdSysRWLock
Definition XrdSysPthread.hh:330