xrootd
XrdSsiShMap.hh
Go to the documentation of this file.
1#ifndef __SSI_SHMAP__
2#define __SSI_SHMAP__
3/******************************************************************************/
4/* */
5/* X r d S s i S h M a p . 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 <stdlib.h>
33#include <string.h>
34
35#include "XrdSsi/XrdSsiShMat.hh"
36
37//-----------------------------------------------------------------------------
41//-----------------------------------------------------------------------------
42
43namespace XrdSsi
44{
45//-----------------------------------------------------------------------------
47//-----------------------------------------------------------------------------
48
50 {ReadOnly = 1,
51 ReadWrite = 2
52 };
53
54//-----------------------------------------------------------------------------
58//-----------------------------------------------------------------------------
59
60static const int ShMap_4Resize = -1;
61
63 {int indexSize;
65 int maxKeys;
66 int mode;
67 int options;
69
70//-----------------------------------------------------------------------------
72//-----------------------------------------------------------------------------
73
74static const
75 int MultW = 0x88000000;
76static const
77 int noMultW = 0x08000000;
78static const
79 int ReUse = 0x44000000;
80static const
81 int noReUse = 0x04000000;
82
83//-----------------------------------------------------------------------------
85//-----------------------------------------------------------------------------
86
87 ShMap_Parms() : indexSize(16381), maxKeyLen(63), maxKeys(32768),
88 mode(0640), options(0), reserved(0) {}
89
90//-----------------------------------------------------------------------------
92//-----------------------------------------------------------------------------
93static const
94 int ForResize = 0;
95
96 ShMap_Parms(int rsz) : indexSize(0), maxKeyLen(0), maxKeys(0),
97 mode(0640), options(0), reserved(rsz) {}
98
99//-----------------------------------------------------------------------------
101//-----------------------------------------------------------------------------
102
104 };
105
106//-----------------------------------------------------------------------------
108//-----------------------------------------------------------------------------
109
111
112//-----------------------------------------------------------------------------
120//-----------------------------------------------------------------------------
121
122typedef int (*ShMap_Hash_t)(const char *key);
123
124template<class T>
125class ShMap
126{
127public:
128
129//-----------------------------------------------------------------------------
147//-----------------------------------------------------------------------------
148
149bool Attach(const char *path, ShMap_Access access, int tmo=-1);
150
151//-----------------------------------------------------------------------------
176//-----------------------------------------------------------------------------
177
178bool Create(const char *path, ShMap_Parms &parms);
179
180//-----------------------------------------------------------------------------
182//-----------------------------------------------------------------------------
183
184void Detach();
185
186//-----------------------------------------------------------------------------
191//-----------------------------------------------------------------------------
192
193bool Export();
194
195//-----------------------------------------------------------------------------
204//-----------------------------------------------------------------------------
205
206bool Add(const char *key, T &val);
207
208//-----------------------------------------------------------------------------
220//-----------------------------------------------------------------------------
221
222bool Del(const char *key, T *valP=0);
223
224//-----------------------------------------------------------------------------
245//-----------------------------------------------------------------------------
246
247bool Enumerate(void *&jar, char *&key, T *&val);
248
249//-----------------------------------------------------------------------------
262//-----------------------------------------------------------------------------
263
264bool Enumerate(void *&jar);
265
266//-----------------------------------------------------------------------------
273//-----------------------------------------------------------------------------
274
275bool Exists(const char *key);
276
277//-----------------------------------------------------------------------------
286//-----------------------------------------------------------------------------
287
288bool Get(const char *key, T &val);
289
290//-----------------------------------------------------------------------------
322//-----------------------------------------------------------------------------
323
324int Info(const char *vname, char *buff=0, int blen=0);
325
326//-----------------------------------------------------------------------------
338//-----------------------------------------------------------------------------
339
340bool Rep(const char *key, T &val, T *valP=0);
341
342//-----------------------------------------------------------------------------
354//-----------------------------------------------------------------------------
355
356bool Resize(ShMap_Parms *parms=0);
357
358//-----------------------------------------------------------------------------
380//-----------------------------------------------------------------------------
381
382bool Sync(SyncOpt dosync, int syncqsz=256);
383
384//-----------------------------------------------------------------------------
399//-----------------------------------------------------------------------------
400
401 ShMap(const char *typeName, ShMap_Hash_t hFunc=0,
402 const char *implName=0)
403 : shMat(0), hashFunc(hFunc), typeID(strdup(typeName)),
404 implID((implName ? strdup(implName) : 0)) {}
405
406//-----------------------------------------------------------------------------
408//-----------------------------------------------------------------------------
409
411 if (typeID) free(typeID);
412 if (implID) free(implID);
413 }
414
415private:
416
419char *typeID;
420char *implID;
421};
422}
423
424/******************************************************************************/
425/* A c t u a l I m p l e m e n t a t i o n */
426/******************************************************************************/
427
428#include "XrdSsi/XrdSsiShMap.icc"
429#endif
#define access(a, b)
Definition: XrdPosix.hh:39
Definition: XrdSsiShMat.hh:42
Definition: XrdSsiShMap.hh:126
void Detach()
Detach the map from the shared memory.
bool Del(const char *key, T *valP=0)
ShMap_Hash_t hashFunc
Definition: XrdSsiShMap.hh:418
bool Get(const char *key, T &val)
bool Attach(const char *path, ShMap_Access access, int tmo=-1)
char * typeID
Definition: XrdSsiShMap.hh:419
~ShMap()
Destructor.
Definition: XrdSsiShMap.hh:410
ShMap(const char *typeName, ShMap_Hash_t hFunc=0, const char *implName=0)
Definition: XrdSsiShMap.hh:401
bool Enumerate(void *&jar, char *&key, T *&val)
XrdSsiShMat * shMat
Definition: XrdSsiShMap.hh:417
bool Rep(const char *key, T &val, T *valP=0)
bool Sync(SyncOpt dosync, int syncqsz=256)
bool Create(const char *path, ShMap_Parms &parms)
bool Enumerate(void *&jar)
char * implID
Definition: XrdSsiShMap.hh:420
bool Exists(const char *key)
int Info(const char *vname, char *buff=0, int blen=0)
bool Add(const char *key, T &val)
bool Resize(ShMap_Parms *parms=0)
Definition: XrdSsiShMap.hh:44
ShMap_Access
The action parameter that must be passed to the Attach() method.
Definition: XrdSsiShMap.hh:50
@ ReadOnly
reading
Definition: XrdSsiShMap.hh:50
@ ReadWrite
reading & writing
Definition: XrdSsiShMap.hh:51
int(* ShMap_Hash_t)(const char *key)
Definition: XrdSsiShMap.hh:122
SyncOpt
Options valid for the Sync() method.
Definition: XrdSsiShMap.hh:110
@ SyncNow
Definition: XrdSsiShMap.hh:110
@ SyncQSz
Definition: XrdSsiShMap.hh:110
@ SyncOn
Definition: XrdSsiShMap.hh:110
@ SyncAll
Definition: XrdSsiShMap.hh:110
@ SyncOff
Definition: XrdSsiShMap.hh:110
static const int ShMap_4Resize
Definition: XrdSsiShMap.hh:60
Definition: XrdSsiShMap.hh:63
static const int MultW
Bit options that may be or'd into he options member above.
Definition: XrdSsiShMap.hh:75
int maxKeys
Maximum expected keys.
Definition: XrdSsiShMap.hh:65
int mode
Mode setting for the newly created file.
Definition: XrdSsiShMap.hh:66
int maxKeyLen
Maximum key length.
Definition: XrdSsiShMap.hh:64
int reserved
Reserved for future ABI complaint use.
Definition: XrdSsiShMap.hh:68
~ShMap_Parms()
Destructor.
Definition: XrdSsiShMap.hh:103
static const int ReUse
Reuse map storage.
Definition: XrdSsiShMap.hh:79
static const int ForResize
Constructor suitable for Resize() (use ShMap_Parms(ForResize)).
Definition: XrdSsiShMap.hh:94
static const int noReUse
Opposite (default for Create)
Definition: XrdSsiShMap.hh:81
static const int noMultW
Opposite (default for Create)
Definition: XrdSsiShMap.hh:77
int options
Bit or'd ShMop_xxxx options below.
Definition: XrdSsiShMap.hh:67
ShMap_Parms(int rsz)
Definition: XrdSsiShMap.hh:96
int indexSize
Number of hash table entries to create.
Definition: XrdSsiShMap.hh:63
ShMap_Parms()
Constructor suitable for Create()
Definition: XrdSsiShMap.hh:87