XRootD
Loading...
Searching...
No Matches
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 <cstdlib>
33#include <cstring>
34
35#include "XrdSsi/XrdSsiShMat.hh"
36
37//-----------------------------------------------------------------------------
41//-----------------------------------------------------------------------------
42
43namespace XrdSsi
44{
45//-----------------------------------------------------------------------------
47//-----------------------------------------------------------------------------
48
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//-----------------------------------------------------------------------------
178//-----------------------------------------------------------------------------
179
180bool Create(const char *path, ShMap_Parms &parms);
181
182//-----------------------------------------------------------------------------
184//-----------------------------------------------------------------------------
185
186void Detach();
187
188//-----------------------------------------------------------------------------
193//-----------------------------------------------------------------------------
194
195bool Export();
196
197//-----------------------------------------------------------------------------
206//-----------------------------------------------------------------------------
207
208bool Add(const char *key, T &val);
209
210//-----------------------------------------------------------------------------
222//-----------------------------------------------------------------------------
223
224bool Del(const char *key, T *valP=0);
225
226//-----------------------------------------------------------------------------
247//-----------------------------------------------------------------------------
248
249bool Enumerate(void *&jar, char *&key, T *&val);
250
251//-----------------------------------------------------------------------------
264//-----------------------------------------------------------------------------
265
266bool Enumerate(void *&jar);
267
268//-----------------------------------------------------------------------------
275//-----------------------------------------------------------------------------
276
277bool Exists(const char *key);
278
279//-----------------------------------------------------------------------------
288//-----------------------------------------------------------------------------
289
290bool Get(const char *key, T &val);
291
292//-----------------------------------------------------------------------------
324//-----------------------------------------------------------------------------
325
326int Info(const char *vname, char *buff=0, int blen=0);
327
328//-----------------------------------------------------------------------------
340//-----------------------------------------------------------------------------
341
342bool Rep(const char *key, T &val, T *valP=0);
343
344//-----------------------------------------------------------------------------
356//-----------------------------------------------------------------------------
357
358bool Resize(ShMap_Parms *parms=0);
359
360//-----------------------------------------------------------------------------
382//-----------------------------------------------------------------------------
383
384bool Sync(SyncOpt dosync, int syncqsz=256);
385
386//-----------------------------------------------------------------------------
401//-----------------------------------------------------------------------------
402
403 ShMap(const char *typeName, ShMap_Hash_t hFunc=0,
404 const char *implName=0)
405 : shMat(0), hashFunc(hFunc), typeID(strdup(typeName)),
406 implID((implName ? strdup(implName) : 0)) {}
407
408//-----------------------------------------------------------------------------
410//-----------------------------------------------------------------------------
411
413 if (typeID) free(typeID);
414 if (implID) free(implID);
415 }
416
417private:
418
419XrdSsiShMat *shMat;
420ShMap_Hash_t hashFunc;
421char *typeID;
422char *implID;
423};
424}
425
426/******************************************************************************/
427/* A c t u a l I m p l e m e n t a t i o n */
428/******************************************************************************/
429
430#include "XrdSsi/XrdSsiShMap.icc"
431#endif
#define access(a, b)
Definition XrdPosix.hh:44
bool Exists
bool Create
void Detach()
Detach the map from the shared memory.
bool Del(const char *key, T *valP=0)
bool Get(const char *key, T &val)
bool Attach(const char *path, ShMap_Access access, int tmo=-1)
~ShMap()
Destructor.
ShMap(const char *typeName, ShMap_Hash_t hFunc=0, const char *implName=0)
bool Enumerate(void *&jar, char *&key, T *&val)
bool Rep(const char *key, T &val, T *valP=0)
bool Sync(SyncOpt dosync, int syncqsz=256)
int Info(const char *vname, char *buff=0, int blen=0)
bool Add(const char *key, T &val)
bool Resize(ShMap_Parms *parms=0)
ShMap_Access
The action parameter that must be passed to the Attach() method.
@ ReadOnly
reading
@ ReadWrite
reading & writing
int(* ShMap_Hash_t)(const char *key)
SyncOpt
Options valid for the Sync() method.
static const int ShMap_4Resize
static const int MultW
Bit options that may be or'd into he options member above.
int maxKeys
Maximum expected keys.
int mode
Mode setting for the newly created file.
int maxKeyLen
Maximum key length.
int reserved
Reserved for future ABI complaint use.
~ShMap_Parms()
Destructor.
static const int ReUse
Reuse map storage.
static const int ForResize
Constructor suitable for Resize() (use ShMap_Parms(ForResize)).
static const int noReUse
Opposite (default for Create)
static const int noMultW
Opposite (default for Create)
int options
Bit or'd ShMop_xxxx options below.
int indexSize
Number of hash table entries to create.
ShMap_Parms()
Constructor suitable for Create()