BaseScheduler Class Reference

This class defines the interface for all scheduler implementations. More...

#include <basescheduler_decls.h>

Inheritance diagram for BaseScheduler:

Microthread NewCoroutine Coroutine RefCounter EpollScheduler SelectScheduler List of all members.

Public Member Functions

virtual void addReadCallback (Callback &cb, int fd)=0
 Tells this Scheduler to run cb when fd is readable.
virtual void addWriteCallback (Callback &cb, int fd)=0
 Tells this Scheduler to run cb when fd is writeable.
virtual void addWaitCallback (Callback &cb, const timeval &tv)=0
 Tells this Scheduler to run cb when tv is reached.
void addRelativeWaitCallback (Callback &cb, const timeval &tv)
 Tells this Scheduler to run cb after a duration of tv.
void scheduleRead (int fd)
 Continues the current thread when fd is readable.
void scheduleWrite (int fd)
 Continues the current thread when fd is writable.
void scheduleWait (const timeval &tv)
 Continues the current thread when tv is reached.
template<class T>
void notifyRead (Channel< T > &chan, const T &value, int fd)
 Sends value to chan when fd is readable.
template<class T>
void notifyWrite (Channel< T > &chan, const T &value, int fd)
 Sends value to chan when fd is writable.
template<class T>
void notifyWait (Channel< T > &chan, const T &value, const timeval &tv)
 Sends value to chan when tv is reached.
virtual void run ()=0
 This method is run when the Microthread gets started.
ssize_t read (int fd, void *buf, size_t count)
 This method behaves like the function described in man 2 read.
ssize_t write (int fd, const void *buf, size_t count)
 This method behaves like the function described in man 2 write.
int accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 This method behaves like the function described in man 2 accept.
int connect (int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
 This method behaves like the function described in man 2 connect.
unsigned int sleep (unsigned int seconds)
 This method behaves like the function described in man 3 sleep.

Protected Member Functions

 BaseScheduler (BlockingQueue< Microthread * > *q=NULL)
 BaseScheduler constructor.

Detailed Description

This class defines the interface for all scheduler implementations.


Constructor & Destructor Documentation

BaseScheduler::BaseScheduler ( BlockingQueue< Microthread * > *  q = NULL  )  [protected]

BaseScheduler constructor.

This class is not instanciateable.

Parameters:
q is the queue passed to the Microthread constructor


Member Function Documentation

virtual void BaseScheduler::addReadCallback ( Callback cb,
int  fd 
) [pure virtual]

Tells this Scheduler to run cb when fd is readable.

This method must be overridden by derived classes. The Callback must not throw an exception when run.

Parameters:
cb is the Callback to be run
fd is the filedescriptor to be monitored

Implemented in EpollScheduler, and SelectScheduler.

virtual void BaseScheduler::addWriteCallback ( Callback cb,
int  fd 
) [pure virtual]

Tells this Scheduler to run cb when fd is writeable.

This method must be overridden by derived classes. The Callback must not throw an exception when run.

Parameters:
cb is the Callback to be run
fd is the filedescriptor to be monitored

Implemented in EpollScheduler, and SelectScheduler.

virtual void BaseScheduler::addWaitCallback ( Callback cb,
const timeval &  tv 
) [pure virtual]

Tells this Scheduler to run cb when tv is reached.

This method must be overridden by derived classes. The Callback must not throw an exception when run.

Parameters:
cb is the Callback to be run
tv is the absolute time to be reached

Implemented in EpollScheduler, and SelectScheduler.

void BaseScheduler::addRelativeWaitCallback ( Callback cb,
const timeval &  tv 
)

Tells this Scheduler to run cb after a duration of tv.

The Callback must not throw an exception when run.

Parameters:
cb is the Callback ti be run
tv is a time interval to be waited

void BaseScheduler::scheduleRead ( int  fd  ) 

Continues the current thread when fd is readable.

Parameters:
fd is the filedescriptor to be monitored

void BaseScheduler::scheduleWrite ( int  fd  ) 

Continues the current thread when fd is writable.

Parameters:
fd is the filedescriptor to be monitored

void BaseScheduler::scheduleWait ( const timeval &  tv  ) 

Continues the current thread when tv is reached.

Parameters:
tv is the absolute time to be reached

template<class T>
void BaseScheduler::notifyRead ( Channel< T > &  chan,
const T &  value,
int  fd 
) [inline]

Sends value to chan when fd is readable.

Parameters:
chan is the Channel to send value on
value is the object to send on chan
fd is the filedescriptor to be monitored

template<class T>
void BaseScheduler::notifyWrite ( Channel< T > &  chan,
const T &  value,
int  fd 
) [inline]

Sends value to chan when fd is writable.

Parameters:
chan is the Channel to send value on
value is the object to send on chan
fd is the filedescriptor to be monitored

template<class T>
void BaseScheduler::notifyWait ( Channel< T > &  chan,
const T &  value,
const timeval &  tv 
) [inline]

Sends value to chan when tv is reached.

Parameters:
chan is the Channel to send value on
value is the object to send on chan
tv is the absolute time to be reached

virtual void BaseScheduler::run (  )  [pure virtual]

This method is run when the Microthread gets started.

It must be overridden by all derived classes.

Implements Microthread.

Implemented in EpollScheduler, and SelectScheduler.

ssize_t BaseScheduler::read ( int  fd,
void *  buf,
size_t  count 
)

This method behaves like the function described in man 2 read.

The only difference is that it first delays the current microthread and continues execution when the filedescriptor is readable so that the read happens non-blocking.

Parameters:
fd is passed to read and scheduled for reading before
buf is passed to read
count is passed to read
Returns:
the value read returns
Exceptions:
ThreadExitException 

ssize_t BaseScheduler::write ( int  fd,
const void *  buf,
size_t  count 
)

This method behaves like the function described in man 2 write.

The only difference is that it first delays the current microthread and continues exaction when the filedescriptor is writable so that the write happens non-blocking.

Parameters:
fd is passed to write and scheduled for writing before
buf is passed to write
count is passed to write
Returns:
the value write returns
Exceptions:
ThreadExitException 

int BaseScheduler::accept ( int  sockfd,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

This method behaves like the function described in man 2 accept.

The only difference is that it first delays the current microthread and continues execution when the filedescriptor is readable so that the accept happens non-blocking.

Parameters:
sockfd is passed to accept and scheduled for reading before
addr is passed to accept
addrlen is passed to accept
Returns:
the value accept returns
Exceptions:
ThreadExitException 

int BaseScheduler::connect ( int  sockfd,
const struct sockaddr *  serv_addr,
socklen_t  addrlen 
)

This method behaves like the function described in man 2 connect.

The only difference is that it first delays the current microthread and continues execution when the filedescriptor is writable so the connect happens non-blocking.

Parameters:
sockfd is passed to connect an scheduled for writing before
serv_addr is passed to connect
addrlen is passed to connect
Returns:
the value connect returns
Exceptions:
ThreadExitException 

unsigned int BaseScheduler::sleep ( unsigned int  seconds  ) 

This method behaves like the function described in man 3 sleep.

It does not put all threads into sleep, only the one currently running is interrupted. This sleep call is not interruptible by signals.

Parameters:
seconds is the time in seconds to sleep
Returns:
0
Exceptions:
ThreadExitException 


The documentation for this class was generated from the following files:
Generated on Sat Feb 7 01:26:51 2009 by  doxygen 1.5.1