/usr/include/root/TMapFile.h is in libroot-io-dev 5.34.14-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | // @(#)root/io:$Id$
// Author: Fons Rademakers 08/07/97
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TMapFile
#define ROOT_TMapFile
//////////////////////////////////////////////////////////////////////////
// //
// TMapFile //
// //
// This class implements a shared memory region mapped to a file. //
// Objects can be placed into this shared memory area using the Add() //
// member function. Whenever the mapped object(s) change(s) call //
// Update() to put a fresh copy in the shared memory. This extra //
// step is necessary since it is not possible to share objects with //
// virtual pointers between processes (the vtbl ptr points to the //
// originators unique address space and can not be used by the //
// consumer process(es)). Consumer processes can map the memory region //
// from this file and access the objects stored in it via the Get() //
// method (which returns a copy of the object stored in the shared //
// memory with correct vtbl ptr set). Only objects of classes with a //
// Streamer() member function defined can be shared. //
// //
//////////////////////////////////////////////////////////////////////////
#ifdef WIN32
#include "Windows4Root.h"
#endif
#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TROOT
#include "TROOT.h"
#endif
#if !defined(__MMPRIVATE_H) && !defined(__CINT__)
#include "mmprivate.h"
#endif
class TBrowser;
class TDirectory;
class TList;
class TMapRec;
class TMapFile : public TObject {
friend class TMapRec;
private:
Int_t fFd; //Descriptor of mapped file
Int_t fVersion; //ROOT version (or -1 for shadow map file)
char *fName; //Name of mapped file
char *fTitle; //Title of mapped file
char *fOption; //Directory creation options
void *fMmallocDesc; //Pointer to mmalloc descriptor
ULong_t fBaseAddr; //Base address of mapped memory region
Int_t fSize; //Original start size of memory mapped region
TMapRec *fFirst; //List of streamed objects is shared memory
TMapRec *fLast; //Last object in list of shared objects
Long_t fOffset; //Offset in bytes for region mapped by reader
TDirectory *fDirectory; //Pointer to directory associated to this mapfile
TList *fBrowseList; //List of KeyMapFile objects
Bool_t fWritable; //TRUE if mapped file opened in RDWR mode
Int_t fSemaphore; //Modification semaphore (or getpid() for WIN32)
ULong_t fhSemaphore; //HANDLE of WIN32 Mutex object to implement semaphore
TObject *fGetting; //Don't deadlock in update mode, when from Get() Add() is called
Int_t fWritten; //Number of objects written sofar
Double_t fSumBuffer; //Sum of buffer sizes of objects written sofar
Double_t fSum2Buffer; //Sum of squares of buffer sizes of objects written so far
static Long_t fgMapAddress; //Map to this address, set address via SetMapAddress()
static void *fgMmallocDesc; //Used in Close() and operator delete()
protected:
TMapFile();
TMapFile(const char *name, const char *title, Option_t *option, Int_t size, TMapFile *&newMapFile);
TMapFile(const TMapFile &f, Long_t offset = 0);
void operator=(const TMapFile &rhs); // not implemented
TMapFile *FindShadowMapFile();
void InitDirectory();
TObject *Remove(TObject *obj, Bool_t lock);
TObject *Remove(const char *name, Bool_t lock);
void SumBuffer(Int_t bufsize);
Int_t GetBestBuffer();
void CreateSemaphore(Int_t pid=0);
Int_t AcquireSemaphore();
Int_t ReleaseSemaphore();
void DeleteSemaphore();
static void *MapToAddress();
public:
enum { kDefaultMapSize = 0x80000 }; // default size of mapped heap is 500 KB
// Should both be protected (waiting for cint)
virtual ~TMapFile();
void operator delete(void *vp);
void Browse(TBrowser *b);
void Close(Option_t *option = "");
void *GetBaseAddr() const { return (void *)fBaseAddr; }
void *GetBreakval() const;
TDirectory *GetDirectory() const {return fDirectory;}
Int_t GetFd() const { return fFd; }
void *GetMmallocDesc() const { return fMmallocDesc; }
const char *GetName() const { return fName; }
Int_t GetSize() const { return fSize; }
const char *GetOption() const { return fOption; }
const char *GetTitle() const { return fTitle; }
TMapRec *GetFirst() const { return (TMapRec*)((Long_t) fFirst + fOffset); }
TMapRec *GetLast() const { return (TMapRec*)((Long_t) fLast + fOffset); }
Bool_t IsFolder() const;
Bool_t IsWritable() const { return fWritable; }
void *OrgAddress(void *addr) const { return (void *)((Long_t)addr - fOffset); }
void Print(Option_t *option="") const;
void ls(Option_t *option="") const;
Bool_t cd(const char *path = 0);
void Add(const TObject *obj, const char *name = "");
void Update(TObject *obj = 0);
TObject *Remove(TObject *obj) { return Remove(obj, kTRUE); }
TObject *Remove(const char *name) { return Remove(name, kTRUE); }
void RemoveAll();
TObject *Get(const char *name, TObject *retObj = 0);
static TMapFile *Create(const char *name, Option_t *option="READ", Int_t size=kDefaultMapSize, const char *title="");
static TMapFile *WhichMapFile(void *addr);
static void SetMapAddress(Long_t addr);
ClassDef(TMapFile,0) // Memory mapped directory structure
};
//////////////////////////////////////////////////////////////////////////
// //
// TMapRec //
// //
// A TMapFile contains a list of TMapRec objects which keep track of //
// the actual objects stored in the mapped file. //
// //
//////////////////////////////////////////////////////////////////////////
class TMapRec {
friend class TMapFile;
private:
char *fName; // object name
char *fClassName; // class name
TObject *fObject; // pointer to original object
void *fBuffer; // buffer containing object of class name
Int_t fBufSize; // buffer size
TMapRec *fNext; // next MapRec in list
TMapRec(const TMapRec&); // Not implemented.
TMapRec &operator=(const TMapRec&); // Not implemented.
public:
TMapRec(const char *name, const TObject *obj, Int_t size, void *buf);
~TMapRec();
const char *GetName(Long_t offset = 0) const { return (char *)((Long_t) fName + offset); }
const char *GetClassName(Long_t offset = 0) const { return (char *)((Long_t) fClassName + offset); }
void *GetBuffer(Long_t offset = 0) const { return (void *)((Long_t) fBuffer + offset); }
Int_t GetBufSize() const { return fBufSize; }
TObject *GetObject() const;
TMapRec *GetNext(Long_t offset = 0) const { return (TMapRec *)((Long_t) fNext + offset); }
};
//______________________________________________________________________________
inline void *TMapFile::GetBreakval() const
{
// Return the current location in the memory region for this malloc heap which
// represents the end of memory in use. Returns 0 if map file was closed.
if (!fMmallocDesc) return 0;
return (void *)((struct mdesc *)fMmallocDesc)->breakval;
}
//______________________________________________________________________________
inline TMapFile *TMapFile::WhichMapFile(void *addr)
{
if (!gROOT || !gROOT->GetListOfMappedFiles()) return 0;
TObjLink *lnk = ((TList *)gROOT->GetListOfMappedFiles())->LastLink();
while (lnk) {
TMapFile *mf = (TMapFile*)lnk->GetObject();
if (!mf) return 0;
if ((ULong_t)addr >= mf->fBaseAddr + mf->fOffset &&
(ULong_t)addr < (ULong_t)mf->GetBreakval() + mf->fOffset)
return mf;
lnk = lnk->Prev();
}
return 0;
}
R__EXTERN void *gMmallocDesc; //is initialized in TClass.cxx
#endif
|