#include <basescheduler_decls.h>
Inheritance diagram for BaseScheduler:
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. |
BaseScheduler::BaseScheduler | ( | BlockingQueue< Microthread * > * | q = NULL |
) | [protected] |
BaseScheduler constructor.
This class is not instanciateable.
q | is the queue passed to the Microthread constructor |
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.
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.
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.
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 | |||
) |
void BaseScheduler::scheduleRead | ( | int | fd | ) |
Continues the current thread when fd is readable.
fd | is the filedescriptor to be monitored |
void BaseScheduler::scheduleWrite | ( | int | fd | ) |
Continues the current thread when fd is writable.
fd | is the filedescriptor to be monitored |
void BaseScheduler::scheduleWait | ( | const timeval & | tv | ) |
Continues the current thread when tv is reached.
tv | is the absolute time to be reached |
void BaseScheduler::notifyRead | ( | Channel< T > & | chan, | |
const T & | value, | |||
int | fd | |||
) | [inline] |
Sends value to chan when fd is readable.
chan | is the Channel to send value on | |
value | is the object to send on chan | |
fd | is the filedescriptor to be monitored |
void BaseScheduler::notifyWrite | ( | Channel< T > & | chan, | |
const T & | value, | |||
int | fd | |||
) | [inline] |
Sends value to chan when fd is writable.
chan | is the Channel to send value on | |
value | is the object to send on chan | |
fd | is the filedescriptor to be monitored |
void BaseScheduler::notifyWait | ( | Channel< T > & | chan, | |
const T & | value, | |||
const timeval & | tv | |||
) | [inline] |
Sends value to chan when tv is reached.
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.
fd | is passed to read and scheduled for reading before | |
buf | is passed to read | |
count | is passed to read |
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.
fd | is passed to write and scheduled for writing before | |
buf | is passed to write | |
count | is passed to write |
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.
sockfd | is passed to accept and scheduled for reading before | |
addr | is passed to accept | |
addrlen | is passed to accept |
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.
sockfd | is passed to connect an scheduled for writing before | |
serv_addr | is passed to connect | |
addrlen | is passed to connect |
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.
seconds | is the time in seconds to sleep |
ThreadExitException |