Loading...
Searching...
No Matches
XrdSys::IOEvents::PollE Class Reference
Inheritance diagram for XrdSys::IOEvents::PollE:
Collaboration diagram for XrdSys::IOEvents::PollE:

## Public Member Functions

| PollE (struct epoll_event *ptab, int numfd, int pfd, int pFD[2])
| ~PollE ()
Public Member Functions inherited from XrdSys::IOEvents::Poller
| Poller (int cFD, int rFD)
virtual | ~Poller ()
| Destructor. Stop() is effecively called when this object is deleted.
void | Stop ()

## Static Public Member Functions

static int | AllocMem (void **memP, int slots)
Static Public Member Functions inherited from XrdSys::IOEvents::Poller
static Poller * | Create (int &eNum, const char **eTxt=0, int crOpts=0)

## Protected Member Functions

void | Begin (XrdSysSemaphore *syncp, int &rc, const char **eMsg)
void | Exclude (Channel *cP, bool &isLocked, bool dover=1)
bool | Include (Channel *cP, int &eNum, const char **eTxt, bool &isLocked)
bool | Modify (Channel *cP, int &eNum, const char **eTxt, bool &isLocked)
void | Shutdown ()
Protected Member Functions inherited from XrdSys::IOEvents::Poller
void | CbkTMO ()
bool | CbkXeq (Channel *cP, int events, int eNum, const char *eTxt)
| CPP_ATOMIC_TYPE (bool) wakePend
int | GetFault (Channel *cP)
int | GetPollEnt (Channel *cP)
int | GetRequest ()
bool | Init (Channel *cP, int &eNum, const char **eTxt, bool &isLockd)
void | LockChannel (Channel *cP)
int | Poll2Enum (short events)
int | SendCmd (PipeData &cmd)
void | SetPollEnt (Channel *cP, int ptEnt)
bool | TmoAdd (Channel *cP, int tmoSet)
void | TmoDel (Channel *cP)
int | TmoGet ()
void | UnLockChannel (Channel *cP)

## Additional Inherited Members

Public Types inherited from XrdSys::IOEvents::Poller
enum | CreateOpts { optTOM }
Protected Attributes inherited from XrdSys::IOEvents::Poller
Channel * | attBase
bool | chDead
int | cmdFD
int | pipeBlen
char * | pipeBuff
struct pollfd | pipePoll
pthread_t | pollTid
PipeData | reqBuff
int | reqFD
Channel * | tmoBase
unsigned char | tmoMask
Static Protected Attributes inherited from XrdSys::IOEvents::Poller
static time_t | maxTime = (sizeof(time_t) == 8 ? 0x7fffffffffffffffLL : 0x7fffffff)
static pid_t | parentPID = getpid()

## Detailed Description

Definition at line 51 of file XrdSysIOEventsPollE.icc.

## Constructor & Destructor Documentation

## PollE()

XrdSys::IOEvents::PollE::PollE | ( | struct epoll_event * | ptab,
|  | int | numfd,
|  | int | pfd,
|  | int | pFD[2] )

inline

Definition at line 57 of file XrdSysIOEventsPollE.icc.

: Poller(pFD[0], pFD[1]), pollTab(ptab), cbNow(0),
pollDfd(pfd), pollMax(numfd), pollNum(1), numPoll(0),
cbCurr(0)
{}
XrdSys::IOEvents::Poller::Poller
Poller(int cFD, int rFD)
Definition XrdSysIOEvents.cc:571

References XrdSys::IOEvents::Poller::Poller().

Here is the call graph for this function:

## ~PollE()

XrdSys::IOEvents::PollE::~PollE | ( |  | ) |

inline

Definition at line 62 of file XrdSysIOEventsPollE.icc.

{Stop();}
XrdSys::IOEvents::Poller::Stop
void Stop()
Definition XrdSysIOEvents.cc:1030

References XrdSys::IOEvents::Poller::Stop().

Here is the call graph for this function:

## Member Function Documentation

## AllocMem()

int XrdSys::IOEvents::PollE::AllocMem | ( | void ** | memP,
|  | int | slots )

static

Definition at line 153 of file XrdSysIOEventsPollE.icc.

{
int rc, bytes, alignment, pagsz = getpagesize();
// Calculate the size of the poll table and allocate it
//
bytes = slots * sizeof(struct epoll_event);
alignment = (bytes < pagsz ? 1024 : pagsz);
if (!(rc = posix_memalign(memP, alignment, bytes))) memset(*memP, 0, bytes);
return rc;
}

## Begin()

void XrdSys::IOEvents::PollE::Begin | ( | XrdSysSemaphore * | syncp,
|  | int & | rc,
|  | const char ** | eTxt )

protected virtual

Start the polling event loop. An implementation must be supplied. Begin() is called via the internal BootStrap class from a new thread.

Implements XrdSys::IOEvents::Poller.

Definition at line 195 of file XrdSysIOEventsPollE.icc.

{
int numpolled, pollN;
Channel *cP;
// Indicate to the starting thread that all went well
//
retcode = 0;
*eTxt = 0;
syncsem->Post();
// Now start dispatching channels that are ready. We use the wakePend flag to
// keep the chatter down when we actually wakeup.
//
do {do {numpolled = epoll_wait(pollDfd, pollTab, pollMax, TmoGet());}
while (numpolled < 0 && errno == EINTR);
CPP_ATOMIC_STORE(wakePend, true, std::memory_order_release);
numPoll = numpolled;
if (numpolled == 0) CbkTMO();
else if (numpolled < 0)
{int rc = errno;
//--------------------------------------------------------------
// If we are in a child process and the epoll file descriptor
// has been closed, there is an immense chance the fork will be
// followed by an exec, in which case we don't want to abort
//--------------------------------------------------------------
if( rc == EBADF && parentPID != getpid() ) return;
std::cerr <<"EPoll: "<<XrdSysE2T(rc)<<" polling for events "<<std::endl;
abort();
}
else for (int i = 0; i < numpolled; i++)
{if ((cP = (Channel *)pollTab[i].data.ptr))
{cbCurr = i; Dispatch(cP, pollTab[i].events);}
else if (!Process(i)) return;
}
pollN = AtomicGet(pollNum);
if (pollMax < pollN) AllocPT(pollN);
} while(1);
}
CPP_ATOMIC_STORE
#define CPP_ATOMIC_STORE(x, val, order)
Definition XrdSysAtomics.hh:96
AtomicGet
#define AtomicGet(x)
Definition XrdSysAtomics.hh:71
XrdSysE2T
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
XrdSys::IOEvents::Poller::TmoGet
int TmoGet()
Definition XrdSysIOEvents.cc:1180
XrdSys::IOEvents::Poller::CbkTMO
void CbkTMO()
Definition XrdSysIOEvents.cc:614
XrdSys::IOEvents::Poller::Channel
friend class Channel
Definition XrdSysIOEvents.hh:374
XrdSys::IOEvents::Poller::parentPID
static pid_t parentPID
Definition XrdSysIOEvents.hh:515

References AtomicGet, XrdSys::IOEvents::Poller::CbkTMO(), XrdSys::IOEvents::Poller::Channel, CPP_ATOMIC_STORE, XrdSys::IOEvents::Poller::parentPID, XrdSysSemaphore::Post(), XrdSys::IOEvents::Poller::TmoGet(), and XrdSysE2T().

Here is the call graph for this function:

## Exclude()

void XrdSys::IOEvents::PollE::Exclude | ( | Channel * | cP,
|  | bool & | isLocked,
|  | bool | dover = 1 )

protected virtual

Remove a channel to the poll set. An implementation must be supplied. The channel is locked when this method is called but must be unlocked by the method if a command is sent to the poller thread and isLocked set to false.

Implements XrdSys::IOEvents::Poller.

Definition at line 282 of file XrdSysIOEventsPollE.icc.

{
// Remove this channel from the poll set. We ignore errors as the descriptor
// may have been closed prior to this call (though this shouldn't happen).
//
epoll_ctl(pollDfd, EPOLL_CTL_DEL, cP->GetFD(), 0);
AtomicDec(pollNum);
// If we need to verify this action, sync with the poller thread (note that the
// poller thread will not ask for this action unless it wants to deadlock). We
// may actually deadlock anyway if the channel lock is held. We are allowed to
// release it if the caller locked it. This will prevent a deadlock. Otherwise,
// if we are in a callback and this channel is not the one that initiated the
// exclude then we must make sure that we cancel any pending callback to the
// excluded channel as it may have been deleted and we won't know that here.
//
if (dover)
{PipeData cmdbuff;
if (isLocked)
{isLocked = false;
UnLockChannel(cP);
}
cmdbuff.req = PipeData::RmFD;
cmdbuff.fd = cP->GetFD();
SendCmd(cmdbuff);
} else {
if (cbNow && cbNow != cP)
for (int i = cbCurr+1; i < numPoll; i++)
{if (cP == (Channel *)pollTab[i].data.ptr)
pollTab[i].data.ptr = &deadChP;
}
}
}
AtomicDec
#define AtomicDec(x)
Definition XrdSysAtomics.hh:68
XrdSys::IOEvents::Poller::SendCmd
int SendCmd(PipeData &cmd)
Definition XrdSysIOEvents.cc:993
XrdSys::IOEvents::Poller::UnLockChannel
void UnLockChannel(Channel *cP)
Definition XrdSysIOEvents.hh:448
XrdSys::IOEvents::Poller::PipeData
Definition XrdSysIOEvents.hh:496
XrdSys::IOEvents::Poller::PipeData::req
char req
Definition XrdSysIOEvents.hh:496

References AtomicDec, XrdSys::IOEvents::Poller::Channel, XrdSys::IOEvents::Poller::PipeData::fd, XrdSys::IOEvents::Channel::GetFD(), XrdSys::IOEvents::Poller::PipeData::req, XrdSys::IOEvents::Poller::SendCmd(), and XrdSys::IOEvents::Poller::UnLockChannel().

Here is the call graph for this function:

## Include()

bool XrdSys::IOEvents::PollE::Include | ( | Channel * | cP,
|  | int & | eNum,
|  | const char ** | eTxt,
|  | bool & | isLocked )

protected virtual

Add a channel to the poll set. An implementation must be supplied. The channel is locked when this method is called but must be unlocked by the method if a command is sent to the poller thread and isLocked set to false.

Implements XrdSys::IOEvents::Poller.

Definition at line 322 of file XrdSysIOEventsPollE.icc.

{
struct epoll_event myEvent = {0, {(void *)cP}};
int events = cP->GetEvents();
// Establish new event mask
//
if (events & Channel:: readEvents) myEvent.events = EPOLLIN | EPOLLPRI;
if (events & Channel::writeEvents) myEvent.events |= EPOLLOUT;
// Add this fd to the poll set
//
if (epoll_ctl(pollDfd, EPOLL_CTL_ADD, cP->GetFD(), &myEvent))
{eNum = errno;
if (eTxt) *eTxt = "adding channel";
return false;
}
// All went well. Bump the number in the set. The poller thread will
// reallocate the poll table if need be.
//
AtomicInc(pollNum);
return true;
}
AtomicInc
#define AtomicInc(x)
Definition XrdSysAtomics.hh:72
XrdSys::IOEvents::Channel::writeEvents
@ writeEvents
Write and Write Timeouts.
Definition XrdSysIOEvents.hh:193
XrdSys::IOEvents::Channel::readEvents
@ readEvents
Read and Read Timeouts.
Definition XrdSysIOEvents.hh:192

References AtomicInc, XrdSys::IOEvents::Channel::GetEvents(), XrdSys::IOEvents::Channel::GetFD(), XrdSys::IOEvents::Channel::readEvents, and XrdSys::IOEvents::Channel::writeEvents.

Here is the call graph for this function:

## Modify()

bool XrdSys::IOEvents::PollE::Modify | ( | Channel * | cP,
|  | int & | eNum,
|  | const char ** | eTxt,
|  | bool & | isLocked )

protected virtual

Modify the event status of a channel. An implementation must be supplied. The channel is locked when this method is called but must be unlocked by the method if a command is sent to the poller thread and isLocked set to false.

Implements XrdSys::IOEvents::Poller.

Definition at line 354 of file XrdSysIOEventsPollE.icc.

{
struct epoll_event myEvents = {0, {(void *)cP}};
int events = cP->GetEvents();
// Establish new event mask
//
if (events & Channel:: readEvents) myEvents.events |= EPOLLIN | EPOLLPRI;
if (events & Channel::writeEvents) myEvents.events |= EPOLLOUT;
// Modify this fd. Unlike solaris, epoll_ctl() does not block when the pollfd
// is being waited upon by another thread.
//
if (epoll_ctl(pollDfd, EPOLL_CTL_MOD, cP->GetFD(), &myEvents))
{eNum = errno;
if (eTxt) *eTxt = "modifying poll events";
return false;
}
// All done
//
return true;
}

References XrdSys::IOEvents::Channel::GetEvents(), XrdSys::IOEvents::Channel::GetFD(), XrdSys::IOEvents::Channel::readEvents, and XrdSys::IOEvents::Channel::writeEvents.

Here is the call graph for this function:

## Shutdown()

void XrdSys::IOEvents::PollE::Shutdown | ( |  | ) |

protected virtual

Shutdown the poller. An implementation must be supplied. The shutdown method must release any allocated storage and close private file descriptors. The polling thread will have already been terminated and x-thread pipe closed. Warning: the derived destructor must call Stop() and do nothing else!

Implements XrdSys::IOEvents::Poller.

Definition at line 413 of file XrdSysIOEventsPollE.icc.

{
static XrdSysMutex shutMutex;
// To avoid race conditions, we serialize this code
//
shutMutex.Lock();
// Release the poll table
//
if (pollTab) {free(pollTab); pollTab = 0;}
// Close the epoll file descriptor
//
if (pollDfd >= 0) {close(pollDfd); pollDfd = -1;}
// All done
//
shutMutex.UnLock();
}
close
#define close(a)
Definition XrdPosix.hh:48
XrdSysMutex::Lock
void Lock()
Definition XrdSysPthread.hh:222
XrdSysMutex::UnLock
void UnLock()
Definition XrdSysPthread.hh:224

References close, XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Here is the call graph for this function:

The documentation for this class was generated from the following file:

- XrdSysIOEventsPollE.icc