12#ifndef BIDIRMMAPPIPE_H
13#define BIDIRMMAPPIPE_H
22#define BEGIN_NAMESPACE_ROOFIT namespace RooFit {
23#define END_NAMESPACE_ROOFIT }
28namespace BidirMMapPipe_impl {
30 class BidirMMapPipeException;
59 static unsigned s_physpgsz;
60 static unsigned s_pagesize;
62 static MMapVariety s_mmapworks;
71 std::list<void*> m_freelist;
77 static unsigned getPageSize();
80 static void* dommap(
unsigned len);
82 static void domunmap(
void*
p,
unsigned len);
84 PageChunk(
const PageChunk&) {}
86 PageChunk&
operator=(
const PageChunk&) {
return *
this; }
89 static unsigned pagesize() {
return s_pagesize; }
91 static unsigned physPgSz() {
return s_physpgsz; }
93 static MMapVariety mmapVariety() {
return s_mmapworks; }
96 PageChunk(PagePool* parent,
unsigned length,
unsigned nPgPerGroup);
102 bool contains(
const Pages&
p)
const;
108 void push(
const Pages&
p);
113 return reinterpret_cast<unsigned char*
>(m_end) -
114 reinterpret_cast<unsigned char*
>(m_begin);
117 unsigned nPagesPerGroup()
const {
return m_nPgPerGrp; }
120 bool empty()
const {
return !m_nUsedGrp; }
123 bool full()
const {
return m_freelist.empty(); }
143 unsigned char m_npages;
157 Pages(
const Pages& other);
167 static unsigned pagesize();
170 unsigned npages()
const {
return m_pimpl->m_npages; }
173 Page* page(
unsigned pgno)
const;
176 Page* operator[](
unsigned pgno)
const {
return page(pgno); }
179 unsigned pageno(Page*
p)
const;
182 unsigned operator[](Page*
p)
const {
return pageno(
p); }
185 void swap(Pages& other)
187 impl*
tmp = other.m_pimpl;
188 other.m_pimpl = m_pimpl;
194 friend class BidirMMapPipe_impl::PageChunk;
197 impl* m_pimpl =
nullptr;
200 Pages(PageChunk* parent, Page* pages,
unsigned npg);
386 typedef std::size_t size_type;
388 typedef BidirMMapPipe_impl::BidirMMapPipeException
Exception;
395 badbit = rderrbit | wrerrbit,
423 BidirMMapPipe(
bool useExceptions =
true,
bool useSocketpair =
false);
435 static int debugflag() {
return s_debugflag; }
441 static void setDebugflag(
int flag) { s_debugflag = flag; }
452 size_type read(
void* addr, size_type sz);
465 size_type write(
const void* addr, size_type sz);
485 size_type bytesReadableNonBlocking();
491 size_type bytesWritableNonBlocking();
506 pid_t pidOtherEnd()
const
507 {
return isChild() ? m_parentPid : m_childPid; }
516 Error = ReadError | WriteError,
519 EndOfFile = ReadEndOfFile | WriteEndOfFile,
522 Invalid = ReadInvalid | WriteInvalid
532 PollEntry(BidirMMapPipe* _pipe) :
533 pipe(_pipe), events(
None), revents(
None) { }
535 PollEntry(BidirMMapPipe* _pipe,
int _events) :
536 pipe(_pipe), events(_events), revents(
None) { }
539 typedef std::vector<PollEntry> PollVector;
679 static int poll(PollVector& pipes,
int timeout);
685 bool isParent()
const {
return m_childPid; }
691 bool isChild()
const {
return !m_childPid; }
697 bool usesSocketpair()
const {
return m_inpipe == m_outpipe; }
703 bool usesPipepair()
const {
return m_inpipe != m_outpipe; }
709 int rdstate()
const {
return m_flags; }
715 bool eof()
const {
return m_flags & eofbit; }
721 bool fail()
const {
return m_flags & failbit; }
727 bool bad()
const {
return m_flags & badbit; }
733 bool good()
const {
return !(m_flags & (eofbit | failbit | badbit)); }
739 bool closed()
const {
return m_flags & failbit; }
747 operator bool()
const {
return !fail() && !bad(); }
753 bool operator!()
const {
return fail() || bad(); }
758#define STREAMOP(TYPE) \
759 BidirMMapPipe& operator<<(const TYPE& val) \
760 { write(&val, sizeof(TYPE)); return *this; } \
761 BidirMMapPipe& operator>>(TYPE& val) \
762 { read(&val, sizeof(TYPE)); return *this; }
769 STREAMOP(
unsigned char);
770 STREAMOP(
unsigned short);
771 STREAMOP(
unsigned int);
772 STREAMOP(
unsigned long);
773 STREAMOP(
unsigned long long);
801 BidirMMapPipe&
operator<<(
const std::string& str);
818 template<
class T> BidirMMapPipe&
operator<<(
const T* tptr)
819 { write(&tptr,
sizeof(tptr));
return *
this; }
829 template<
class T> BidirMMapPipe&
operator>>(T* &tptr)
830 { read(&tptr,
sizeof(tptr));
return *
this; }
842 BidirMMapPipe&
operator<<(BidirMMapPipe& (*manip)(BidirMMapPipe&))
843 {
return manip(*
this); }
855 BidirMMapPipe&
operator>>(BidirMMapPipe& (*manip)(BidirMMapPipe&))
856 {
return manip(*
this); }
859 static BidirMMapPipe& flush(BidirMMapPipe& pipe) { pipe.flush();
return pipe; }
861 static BidirMMapPipe& purge(BidirMMapPipe& pipe) { pipe.purge();
return pipe; }
865 BidirMMapPipe(
const BidirMMapPipe&);
867 BidirMMapPipe&
operator=(
const BidirMMapPipe&) {
return *
this; }
870 friend class BidirMMapPipe_impl::Page;
872 typedef BidirMMapPipe_impl::Page Page;
881 PagesPerEnd = TotPages / 2,
885 FlushThresh = (3 * PagesPerEnd) / 4
889 static pthread_mutex_t s_openpipesmutex;
891 static std::list<BidirMMapPipe*> s_openpipes;
893 static BidirMMapPipe_impl::PagePool* s_pagepool;
895 static unsigned s_pagepoolrefcnt;
897 static int s_debugflag;
900 static BidirMMapPipe_impl::PagePool& pagepool();
903 BidirMMapPipe_impl::Pages m_pages;
914 static void teardownall(
void);
917 static unsigned lenPageList(
const Page* list);
927 void feedPageLists(Page* plist);
930 void markPageDirty(Page*
p);
933 static size_type xferraw(
int fd,
void* addr, size_type
len,
934 ssize_t (*xferfn)(
int,
void*, std::size_t));
936 static size_type xferraw(
int fd,
void* addr,
const size_type
len,
937 ssize_t (*xferfn)(
int,
const void*, std::size_t))
939 return xferraw(fd, addr,
len,
940 reinterpret_cast<ssize_t (*)(
941 int,
void*, std::size_t)
>(xferfn));
954 void sendpages(Page* plist);
966 unsigned recvpages();
975 unsigned recvpages_nonblock();
983 int doClose(
bool force,
bool holdlock =
false);
985 void doFlush(
bool forcePartialPages =
true);
991#undef BEGIN_NAMESPACE_ROOFIT
992#undef END_NAMESPACE_ROOFIT
ROOT::R::TRInterface & Exception()
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
TBuffer & operator>>(TBuffer &buf, Tmpl *&obj)
TCut operator!(const TCut &rhs)
Logical negation.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Binding & operator=(OUT(*fun)(void))
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
void Copy(void *source, void *dest)