xrootd
Loading...
Searching...
No Matches
XrdSsiShMam.hh
Go to the documentation of this file.
1#ifndef __SSI_SHMAM__
2#define __SSI_SHMAM__
3/******************************************************************************/
4/* */
5/* X r d S s i S h M a m . h h */
6/* */
7/* (c) 2015 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* Produced by Andrew Hanushevsky for Stanford University under contract */
9/* DE-AC02-76-SFO0515 with the Department of Energy */
10/* */
11/* This file is part of the XRootD software suite. */
12/* */
13/* XRootD is free software: you can redistribute it and/or modify it under */
14/* the terms of the GNU Lesser General Public License as published by the */
15/* Free Software Foundation, either version 3 of the License, or (at your */
16/* option) any later version. */
17/* */
18/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21/* License for more details. */
22/* */
23/* You should have received a copy of the GNU Lesser General Public License */
24/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26/* */
27/* The copyright holder's institutional names and contributor's names may not */
28/* be used to endorse or promote products derived from this software without */
29/* specific prior written permission of the institution or contributor. */
30/******************************************************************************/
31
32#include <pthread.h>
33
35#include "XrdSsi/XrdSsiShMat.hh"
36
38{
39public:
40
41bool AddItem(void *newdata, void *olddata, const char *key,
42 int hash, bool replace=false);
43
44bool Attach(int tout, bool isrw=false);
45
47
48bool Export();
49
50bool DelItem(void *data, const char *key, int hash);
51
52void Detach();
53
54bool Enumerate(void *&jar, char *&key, void *&val);
55
56bool Enumerate(void *&jar);
57
58bool GetItem(void *data, const char *key, int hash);
59
60int Info(const char *vname, char *buff=0, int blen=0);
61
63
64bool Sync();
65bool Sync(bool dosync, bool syncdo);
66bool Sync(int syncqsz);
67
69
71 pthread_mutex_destroy(&lkMutex);
72 pthread_rwlock_destroy(&myMutex);
73 }
74
75enum LockType {ROLock= 0, RWLock = 1};
76
77private:
78struct MemItem {int hash; Atomic(int) next;};
79
80bool ExportIt(bool fLocked);
81int Find(MemItem *&theItem, MemItem *&prvItem, const char *key, int &hash);
82bool Flush();
83int HashVal(const char *key);
84bool Lock(bool doRW=false, bool nowait=false);
86bool ReMap(LockType iHave);
87void RetItem(MemItem *iP);
88void SetLocking(bool isrw);
89void SwapMap(XrdSsiShMam &newMap);
90void Snooze(int sec);
91void UnLock(bool isrw);
92void Updated(int mOff);
93void Updated(int mOff, int mLen);
94
96{
97public:
98inline bool FLock() {if (!(shmemP->Lock(lkType))) return false;
99 doUnLock = true; return true;
100 }
101
103 : shmemP(shmemp), lkType(lktype), doUnLock(false)
104 {if (lktype == RWLock)
105 pthread_rwlock_wrlock(&(shmemP->myMutex));
106 else pthread_rwlock_rdlock(&(shmemP->myMutex));
107 }
108 ~XLockHelper() {int rc = errno;
109 if (lkType == RWLock && shmemP->syncOn
111 shmemP-> Flush();
113 pthread_rwlock_unlock(&(shmemP->myMutex));
114 errno = rc;
115 }
116private:
120};
121
122pthread_mutex_t lkMutex;
123pthread_rwlock_t myMutex;
124
126long long shmSize;
128Atomic(int)*shmIndex;
143bool isRW;
146bool reUse;
147bool multW;
151};
152#endif
Definition XrdSsiShMam.hh:96
~XLockHelper()
Definition XrdSsiShMam.hh:108
bool doUnLock
Definition XrdSsiShMam.hh:119
XrdSsiShMam * shmemP
Definition XrdSsiShMam.hh:117
XLockHelper(XrdSsiShMam *shmemp, LockType lktype)
Definition XrdSsiShMam.hh:102
bool FLock()
Definition XrdSsiShMam.hh:98
LockType lkType
Definition XrdSsiShMam.hh:118
Definition XrdSsiShMam.hh:38
bool lockRW
Definition XrdSsiShMam.hh:145
XrdSsiShMam(XrdSsiShMat::NewParms &parms)
int shmItemSz
Definition XrdSsiShMam.hh:130
bool Resize(XrdSsiShMat::CRZParms &parms)
int syncQSZ
Definition XrdSsiShMam.hh:141
bool Create(XrdSsiShMat::CRZParms &parms)
char * shmBase
Definition XrdSsiShMam.hh:127
bool isRW
Definition XrdSsiShMam.hh:143
bool useAtomic
Definition XrdSsiShMam.hh:148
void UnLock(bool isrw)
int shmFD
Definition XrdSsiShMam.hh:135
Atomic(int) *shmIndex
bool Sync(int syncqsz)
void Detach()
Detach the map from the shared memory.
bool AddItem(void *newdata, void *olddata, const char *key, int hash, bool replace=false)
MemItem * NewItem()
bool syncBase
Definition XrdSsiShMam.hh:149
bool DelItem(void *data, const char *key, int hash)
int accMode
Definition XrdSsiShMam.hh:142
bool Enumerate(void *&jar)
int verNum
Definition XrdSsiShMam.hh:132
int syncOpt
Definition XrdSsiShMam.hh:138
pthread_rwlock_t myMutex
Definition XrdSsiShMam.hh:123
bool lockRO
Definition XrdSsiShMam.hh:144
bool Lock(bool doRW=false, bool nowait=false)
bool Flush()
bool Sync(bool dosync, bool syncdo)
bool ReMap(LockType iHave)
int shmInfoSz
Definition XrdSsiShMam.hh:131
int syncLast
Definition XrdSsiShMam.hh:140
int Info(const char *vname, char *buff=0, int blen=0)
void Snooze(int sec)
~XrdSsiShMam()
Definition XrdSsiShMam.hh:70
void SwapMap(XrdSsiShMam &newMap)
bool GetItem(void *data, const char *key, int hash)
int shmSlots
Definition XrdSsiShMam.hh:129
void SetLocking(bool isrw)
LockType
Definition XrdSsiShMam.hh:75
@ RWLock
Definition XrdSsiShMam.hh:75
@ ROLock
Definition XrdSsiShMam.hh:75
int keyPos
Definition XrdSsiShMam.hh:133
bool multW
Definition XrdSsiShMam.hh:147
char * shmTemp
Definition XrdSsiShMam.hh:125
pthread_mutex_t lkMutex
Definition XrdSsiShMam.hh:122
int HashVal(const char *key)
bool Attach(int tout, bool isrw=false)
bool Export()
long long shmSize
Definition XrdSsiShMam.hh:126
void Updated(int mOff, int mLen)
bool Enumerate(void *&jar, char *&key, void *&val)
void RetItem(MemItem *iP)
int syncQWR
Definition XrdSsiShMam.hh:139
void Updated(int mOff)
int timeOut
Definition XrdSsiShMam.hh:136
int lkCount
Definition XrdSsiShMam.hh:137
bool syncOn
Definition XrdSsiShMam.hh:150
int maxKLen
Definition XrdSsiShMam.hh:134
int Find(MemItem *&theItem, MemItem *&prvItem, const char *key, int &hash)
bool reUse
Definition XrdSsiShMam.hh:146
bool ExportIt(bool fLocked)
Definition XrdSsiShMat.hh:42
Definition XrdSsiShMam.hh:78
int hash
Definition XrdSsiShMam.hh:78
Definition XrdSsiShMat.hh:100
Definition XrdSsiShMat.hh:277