10 #ifndef BIDIRMMAPPIPE_H 11 #define BIDIRMMAPPIPE_H 19 #define BEGIN_NAMESPACE_ROOFIT namespace RooFit { 20 #define END_NAMESPACE_ROOFIT } 27 class BidirMMapPipeException;
93 PageChunk(PagePool* parent,
unsigned length,
unsigned nPgPerGroup);
110 return reinterpret_cast<unsigned char*
>(
m_end) -
111 reinterpret_cast<unsigned char*>(m_begin);
120 bool full()
const {
return m_freelist.empty(); }
167 unsigned npages()
const {
return m_pimpl->m_npages; }
170 Page* page(
unsigned pgno)
const;
176 unsigned pageno(Page* p)
const;
385 typedef BidirMMapPipe_impl::BidirMMapPipeException
Exception;
392 badbit = rderrbit | wrerrbit,
420 BidirMMapPipe(
bool useExceptions =
true,
bool useSocketpair =
false);
449 size_type
read(
void* addr, size_type sz);
462 size_type
write(
const void* addr, size_type sz);
482 size_type bytesReadableNonBlocking();
488 size_type bytesWritableNonBlocking();
504 {
return isChild() ? m_parentPid : m_childPid; }
516 EndOfFile = ReadEndOfFile | WriteEndOfFile,
519 Invalid = ReadInvalid | WriteInvalid
530 pipe(_pipe), events(
None), revents(
None) { }
533 pipe(_pipe), events(_events), revents(
None) { }
676 static int poll(PollVector& pipes,
int timeout);
712 bool eof()
const {
return m_flags & eofbit; }
718 bool fail()
const {
return m_flags & failbit; }
724 bool bad()
const {
return m_flags & badbit; }
730 bool good()
const {
return !(m_flags & (eofbit | failbit | badbit)); }
736 bool closed()
const {
return m_flags & failbit; }
744 operator bool()
const {
return !fail() && !bad(); }
755 #define STREAMOP(TYPE) \ 756 BidirMMapPipe& operator<<(const TYPE& val) \ 757 { write(&val, sizeof(TYPE)); return *this; } \ 758 BidirMMapPipe& operator>>(TYPE& val) \ 759 { read(&val, sizeof(TYPE)); return *this; } 816 {
write(&tptr,
sizeof(tptr));
return *
this; }
827 {
read(&tptr,
sizeof(tptr));
return *
this; }
840 {
return manip(*
this); }
853 {
return manip(*
this); }
867 friend class BidirMMapPipe_impl::Page;
869 typedef BidirMMapPipe_impl::Page
Page;
878 PagesPerEnd = TotPages / 2,
882 FlushThresh = (3 * PagesPerEnd) / 4
897 static BidirMMapPipe_impl::PagePool& pagepool();
911 static void teardownall(
void);
914 static unsigned lenPageList(
const Page* list);
924 void feedPageLists(Page* plist);
927 void markPageDirty(Page* p);
930 static size_type xferraw(
int fd,
void* addr, size_type
len,
931 ssize_t (*xferfn)(
int,
void*, std::size_t));
933 static size_type
xferraw(
int fd,
void* addr,
const size_type len,
934 ssize_t (*xferfn)(
int,
const void*, std::size_t))
936 return xferraw(fd, addr, len,
937 reinterpret_cast<ssize_t (*)(
938 int,
void*, std::size_t)
>(xferfn));
951 void sendpages(Page* plist);
963 unsigned recvpages();
972 unsigned recvpages_nonblock();
980 int doClose(
bool force,
bool holdlock =
false);
982 void doFlush(
bool forcePartialPages =
true);
988 #undef BEGIN_NAMESPACE_ROOFIT 989 #undef END_NAMESPACE_ROOFIT 991 #endif // BIDIRMMAPPIPE_H std::size_t size_type
type used to represent sizes
bool usesSocketpair() const
if BidirMMapPipe uses a socketpair for communications
#define BEGIN_NAMESPACE_ROOFIT
PagePool * m_parent
parent page pool
unsigned char m_npages
length in pages
double read(const std::string &file_name)
reading
BidirMMapPipe & operator<<(const T *tptr)
write raw pointer to T to other side
BidirMMapPipe * pipe
pipe of interest
PollEntry(BidirMMapPipe *_pipe, int _events)
poll a pipe for specified events
unsigned revents
events that happened (or'ed bitmask)
bool empty() const
return true if no used page groups in this chunk
double write(int n, const std::string &file_name, const std::string &vector_type, int compress=0)
writing
handle class for a number of Pages
PageChunk(const PageChunk &)
forbid copying
impl * m_pimpl
pointer to implementation
unsigned m_refcnt
reference counter
bool bad() const
true on I/O error
Page * m_freelist
linked list: free pages
don't know yet what'll work
BidirMMapPipeException Exception
convenience typedef
namespace for implementation details of BidirMMapPipe
unsigned events
events of interest (or'ed bitmask)
bool isChild() const
return if this end of the pipe is the child end
int rdstate() const
return flags (end of file, BidirMMapPipe closed, ...)
PollEntry(BidirMMapPipe *_pipe)
poll a pipe for all events
static MMapVariety s_mmapworks
mmap variety that works on this system
unsigned m_nUsedGrp
number of used page groups
bool fail() const
logical failure (e.g.
pid_t m_childPid
pid of the child (zero if we're child)
static size_type xferraw(int fd, void *addr, const size_type len, ssize_t(*xferfn)(int, const void *, std::size_t))
transfer bytes through the pipe (reading, writing, may block)
bool usesPipepair() const
if BidirMMapPipe uses a pipe pair for communications
TBuffer & operator>>(TBuffer &buf, Tmpl *&obj)
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
mmapping a temp file works
class representing a chunk of pages
Page * m_busylist
linked list: busy pages (data to be read)
static MMapVariety mmapVariety()
return mmap variety support found
void flush()
flush buffers with unwritten data
BidirMMapPipe_impl::Page Page
convenience typedef for Page
Page * m_dirtylist
linked list: dirty pages (data to be sent)
PollFlags
condition flags for poll
#define END_NAMESPACE_ROOFIT
static unsigned physPgSz()
return the physical page size of the system
unsigned nPagesPerGroup() const
return number of pages per page group
Pages()
default constructor
static unsigned s_physpgsz
system physical page size
void swap(Pages &other)
swap with other's contents
void purge()
purge buffered data waiting to be read and/or written
std::vector< PollEntry > PollVector
convenience typedef for poll() interface
void Error(const char *location, const char *msgfmt,...)
static int debugflag()
return the current setting of the debug flag
unsigned m_nPgPerGrp
number of pages per group
bool eof() const
true if end-of-file
BidirMMapPipe & operator=(const BidirMMapPipe &)
assignment forbidden
static BidirMMapPipe & purge(BidirMMapPipe &pipe)
for usage a la "pipe << purge;"
Pages pop()
pop a group of pages off the free list
static void setDebugflag(int flag)
set the debug flags
int m_outpipe
pipe end to which data may be written
void * m_begin
pointer to start of mmapped area
static BidirMMapPipe & flush(BidirMMapPipe &pipe)
for usage a la "pipe << flush;"
bool isParent() const
return if this end of the pipe is the parent end
BidirMMapPipe creates a bidirectional channel between the current process and a child it forks...
pid_t m_parentPid
pid of the parent
static void domunmap(void *p, unsigned len)
munmap pages p, len is length of mmapped area in bytes
static pthread_mutex_t s_openpipesmutex
protects s_openpipes
static int s_debugflag
debug flag
static BidirMMapPipe_impl::PagePool * s_pagepool
pool of mmapped pages
Page * operator[](unsigned pgno) const
return page number pageno
MMapVariety
type of mmap support found
PageChunk & operator=(const PageChunk &)
forbid assignment
void zap(Pages &p)
free all pages except for those pointed to by p
static void * dommap(unsigned len)
mmap pages, len is length of mmapped area in bytes
static unsigned getPageSize()
determine page size at run time
bool contains(const Pages &p) const
return if p is contained in this PageChunk
std::list< void * > m_freelist
free pages list
unsigned len() const
return length of chunk
bool operator!() const
return true if serious error (fail/bad)
void * m_end
pointer one behind end of mmapped area
PageChunk * m_parent
pointer to parent pool
BidirMMapPipe_impl::BidirMMapPipeException Exception
convenience typedef for BidirMMapPipeException
unsigned npages() const
return number of pages accessible
unsigned operator[](Page *p) const
perform page to page number mapping
void push(const Pages &p)
push a group of pages onto the free list
int m_inpipe
pipe end from which data may be read
BidirMMapPipe & operator>>(T *&tptr)
read raw pointer to T from other side
BidirMMapPipe & operator<<(BidirMMapPipe &(*manip)(BidirMMapPipe &))
I/O manipulator support.
Page * m_pages
pointer to first page
BidirMMapPipe_impl::Pages m_pages
mmapped pages
static std::list< BidirMMapPipe * > s_openpipes
list of open BidirMMapPipes
static unsigned s_pagepoolrefcnt
page pool reference counter
static unsigned s_pagesize
logical page size (run-time determined)
bool full() const
return true if no free page groups in this chunk
bool good() const
status of stream is good
pid_t pidOtherEnd() const
return PID of the process on the other end of the pipe
bool closed() const
true if closed
int m_flags
flags (e.g. end of file)
BidirMMapPipe & operator>>(BidirMMapPipe &(*manip)(BidirMMapPipe &))
I/O manipulator support.
mmap doesn't work, have to copy back and forth
static unsigned pagesize()
return the logical page size