12#pragma optimize("",off)
67# ifdef CreateSemaphore
68# undef CreateSemaphore
71# ifdef AcquireSemaphore
72# undef AcquireSemaphore;
75# ifdef ReleaseSemaphore
76# undef ReleaseSemaphore
79# ifdef DeleteSemaphore
80# undef DeleteSemaphore
84# define INVALID_HANDLE_VALUE -1
101#include "mmprivate.h"
105#if defined(R__UNIX) && !defined(R__WINGCC)
107#include <sys/types.h>
110#if !defined(WIN32) && !defined(R__MACOSX)
113 struct semid_ds *buf;
117#if defined(R__LINUX) || defined(R__LYNXOS) || defined(R__HURD)
133 static bool FreeIfTMapFile(
void* ptr) {
135 if (mf->IsWritable())
136 ::mfree(mf->GetMmallocDesc(), ptr);
144 static void *GetMapFileMallocDesc(
void *userptr)
148 return mf->GetMmallocDesc();
269 char *cleanup =
nullptr;
285 if (!create && !recreate && !
update && !read) {
296 Error(
"TMapFile",
"error expanding path %s",
name);
309 Error(
"TMapFile",
"file %s already exists", fname);
318 Error(
"TMapFile",
"no write permission, could not open file %s", fname);
324 Error(
"TMapFile",
"file %s does not exist", fname);
328 Error(
"TMapFile",
"no read permission, could not open file %s", fname);
336 fFd = open(fname, O_RDWR | O_CREAT, 0666);
339 GENERIC_WRITE | GENERIC_READ,
340 FILE_SHARE_WRITE | FILE_SHARE_READ,
343 FILE_ATTRIBUTE_TEMPORARY,
347 SysError(
"TMapFile",
"file %s can not be opened", fname);
353 fFd = open(fname, O_RDONLY);
357 FILE_SHARE_WRITE | FILE_SHARE_READ,
360 FILE_ATTRIBUTE_TEMPORARY,
364 SysError(
"TMapFile",
"file %s can not be opened for reading", fname);
381 if (mapto == (
void *)-1) {
382 Error(
"TMapFile",
"no memory mapped file capability available\n"
383 "Use rootn.exe or link application against \"-lNew\"");
386 Error(
"TMapFile",
"mapped file not in mmalloc format or\n"
387 "already open in RW mode by another process");
389 Error(
"TMapFile",
"mapped file not in mmalloc format");
394 CloseHandle((HANDLE)
fFd);
409 Error(
"TMapFile",
"map file %s (%d) incompatible with current ROOT version (%d)",
415 CloseHandle((HANDLE)
fFd);
423 Warning(
"TMapFile",
"map file already open in write mode, opening in read-only mode");
462 gROOT->GetListOfMappedFiles()->AddLast(
this);
469 Error(
"TMapFile",
"map file is not writable");
474 CloseHandle((HANDLE)
fFd);
495 gROOT->GetListOfMappedFiles()->AddLast(
this);
502 gROOT->GetListOfMappedFiles()->AddFirst(mapfil);
505 if (cleanup)
delete [] cleanup;
648 char *MemMapAllocFunc(
char *oldptr,
size_t newsize,
size_t oldsize)
667 if (all || mr->
fObject == obj) {
708 if (mr->fObject == obj) {
747 if (!strcmp(mr->fName,
name)) {
757 retObj = mr->fObject;
854 fSemaphore = semget(IPC_PRIVATE, 1, SEM_R|SEM_A|(SEM_R>>3)|(SEM_A>>3)|
855 (SEM_R>>6)|(SEM_A>>6));
864 char buffer[] =
"ROOT_Semaphore_xxxxxxxx";
865 int lbuf = strlen(buffer);
886 semctl(semid, 0, IPC_RMID,
set);
906 struct sembuf buf = { 0, -1, SEM_UNDO };
910#if defined(R__FBSD) || defined(R__OBSD)
937 Error(
"AcquireSemaphore",
"cannot update mapping");
951 struct sembuf buf = { 0, 1, SEM_UNDO };
953#if defined(R__FBSD) || defined(R__OBSD)
984 Error(
"Close",
"shadow map == 0, should never happen!");
990 gROOT->GetListOfMappedFiles()->Remove(shadow);
991 gROOT->GetListOfMappedFiles()->Remove(
this);
1000 if (strcmp(option,
"dtor"))
1010 if (shadow->
fFd != -1)
1014 CloseHandle((HANDLE)shadow->
fFd);
1047 (
float)
size/1048576);
1050 Printf(
"Option: file closed");
1106 ((
TMapFile*)
this)->AcquireSemaphore();
1108 Printf(
"%-20s %-20s %-10s",
"Object",
"Class",
"Size");
1110 Printf(
"*** no objects stored in memory mapped file ***");
1119 ((
TMapFile*)
this)->ReleaseSemaphore();
1146 return (
Int_t)(mean + std::sqrt(rms2));
1156 return (
void *)((
struct mdesc *)
fMmallocDesc)->breakval;
1246void TMapFile::operator
delete(
void *ptr)
1251 TObject::operator
delete(ptr);
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
unsigned long ULongptr_t
Unsigned integer large enough to hold a pointer (platform-dependent).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
const char Option_t
Option string (const char).
struct SetFreeIfTMapFile_t gSetFreeIfTMapFile
#define INVALID_HANDLE_VALUE
externTVirtualMutex * gROOTMutex
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
char * StrDup(const char *str)
Duplicate the string str.
#define R__LOCKGUARD(mutex)
Using a TBrowser one can browse all ROOT objects.
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
TClass instances represent classes, structs and namespaces in the ROOT type system.
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Utility class for browsing TMapFile objects.
static TMapFile * WhichMapFile(void *addr)
void * GetBreakval() const
Return the current location in the memory region for this malloc heap which represents the end of mem...
Int_t fWritten
Number of objects written so far.
static TMapFile * Create(const char *name, Option_t *option="READ", Int_t size=kDefaultMapSize, const char *title="")
Create a memory mapped file.
TMapRec * fLast
Last object in list of shared objects.
Int_t fVersion
ROOT version (or -1 for shadow map file).
Bool_t IsFolder() const override
Returns kTRUE in case object is a folder (i.e. contains browsable lists).
ULongptr_t fBaseAddr
Base address of mapped memory region.
const char * GetName() const override
Returns name of object.
void ls(Option_t *option="") const override
List contents of TMapFile.
TDirectory * fDirectory
Pointer to directory associated to this mapfile.
void SumBuffer(Int_t bufsize)
Increment statistics for buffer sizes of objects in this file.
const char * GetTitle() const override
Returns title of object.
TObject * Get(const char *name, TObject *retObj=nullptr)
Return pointer to object retrieved from shared memory.
void Print(Option_t *option="") const override
Print some info about the mapped file.
char * fTitle
Title of mapped file.
void InitDirectory()
Create the directory associated to this mapfile.
void RemoveAll()
Remove all objects from shared memory.
Double_t fSum2Buffer
Sum of squares of buffer sizes of objects written so far.
Bool_t fWritable
TRUE if mapped file opened in RDWR mode.
Longptr_t fOffset
Offset in bytes for region mapped by reader.
void Close(Option_t *option="") override
Close a mapped file.
void * OrgAddress(void *addr) const
Bool_t cd(const char *path=nullptr)
Cd to associated directory.
void DeleteSemaphore()
Delete the semaphore.
Longptr_t fSemaphore
Modification semaphore (or getpid() for WIN32).
TList * fBrowseList
List of KeyMapFile objects.
TMapRec * fFirst
List of streamed objects is shared memory.
~TMapFile() override
TMapFiles may not be deleted, since we want to keep the complete TMapFile object in the mapped file f...
ULongptr_t fhSemaphore
HANDLE of WIN32 Mutex object to implement semaphore.
static void * MapToAddress()
Return the base address at which we would like the next TMapFile's mapped data to start.
void Update(TObject *obj=nullptr)
Update an object (or all objects, if obj == 0) in shared memory.
TObject * fGetting
Don't deadlock in update mode, when from Get() Add() is called.
TMapFile * FindShadowMapFile()
Returns shadow map file.
void * fMmallocDesc
Pointer to mmalloc descriptor.
Double_t fSumBuffer
Sum of buffer sizes of objects written so far.
static void * fgMmallocDesc
Used in Close() and operator delete().
void CreateSemaphore(Int_t pid=0)
Create semaphore used for synchronizing access to shared memory.
Longptr_t fFd
Descriptor of mapped file.
Int_t fSize
Original start size of memory mapped region.
TObject * Remove(TObject *obj, Bool_t lock)
Remove object from shared memory.
Int_t ReleaseSemaphore()
Release semaphore. Returns 0 if OK, -1 on error.
static void SetMapAddress(Longptr_t addr)
Set preferred map address.
char * fName
Name of mapped file.
TMapFile()
Default ctor. Does not much except setting some basic values.
char * fOption
Directory creation options.
Int_t AcquireSemaphore()
Acquire semaphore. Returns 0 if OK, -1 on error.
void Browse(TBrowser *b) override
Browse contents of TMapFile.
void Add(const TObject *obj, const char *name="")
Add an object to the list of objects to be stored in shared memory.
static Longptr_t fgMapAddress
Map to this address, set address via SetMapAddress().
Int_t GetBestBuffer()
Return the best buffer size for objects in this file.
TMapRec * GetFirst() const
TObject * fObject
Pointer to original object.
Int_t fBufSize
Buffer size.
TMapRec(const TMapRec &)=delete
const char * GetClassName(Longptr_t offset=0) const
TMapRec * fNext
Next MapRec in list.
TObject * GetObject() const
This method returns a pointer to the original object.
const char * GetName(Longptr_t offset=0) const
TMapRec * GetNext(Longptr_t offset=0) const
void * GetBuffer(Longptr_t offset=0) const
char * fClassName
Class name.
void * fBuffer
Buffer containing object of class name.
const char * GetName() const override
Returns name of object.
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
static void SetDtorOnly(void *obj)
Set destructor only flag.
TObject()
TObject constructor.
static Bool_t HasCustomNewDelete()
return the has custom delete flag
static void * ReAlloc(void *vp, size_t size, size_t oldsize)
Reallocate (i.e.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
static void ResetErrno()
Static function resetting system error number.
static Int_t GetErrno()
Static function returning system error number.
Abstract base class for TMapFile.
externGetMapFileMapllocDesc_t * gGetMapFileMallocDesc
externFreeIfTMapFile_t * gFreeIfTMapFile
externvoid * gMmallocDesc