Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | Namespace Members | Class Members

POSIX_Simulator Class Reference

#include <simulator/posix/posix_simulator.h>

Inheritance diagram for POSIX_Simulator:

Inheritance graph
[legend]
Collaboration diagram for POSIX_Simulator:

Collaboration graph
[legend]
List of all members.

Detailed Description

Implements the thread, semaphore, timer and mutex functions used in the base Simulator class using POSIX functions.

Author:
Nicolas Brodu


Public Member Functions

virtual void start (bool threaded=true)
 Start processing events at a rate determined by the time factor.
virtual double getSystemTime ()
 Override this method to return the current system time, expressed in system time units (usually seconds).

Protected Member Functions

virtual void eventMutexLock ()
 Override this method to lock the mutex that will be used for event related functions.
virtual void eventMutexUnlock ()
 Override this method to unlock the mutex that will be used for event related functions No locking by default, see CPP.
virtual bool stepControlMutexTryLock ()
 Override this method to try locking a mutex that will be used for controlling the simulation.
virtual void stepControlMutexLock ()
 Override this method to locking the mutex that will be used for controlling the simulation.
virtual void stepControlMutexUnlock ()
 Override this method to unlock the mutex that will be used for controlling the simulation.
virtual void waitSemaphorePost ()
 Override this method to increment a semaphore that will be used for waiting for a new event in the event loop.
virtual void waitSemaphoreFlush ()
 Override this method to flush a semaphore that will be used for waiting for a new event in the event loop.
virtual void waitSemaphoreWait ()
 Override this method to implement the "standard wait till semaphore count >0" call on a semaphore that will be used for waiting for a new event in the event loop.
virtual void startWaitTimer (double delay)
 Override this method to start some kind of timer, that will call the timer callback provided after the given delay.
virtual void cancelWaitTimer ()
 Override this method to immediately stop the timer started by the startWaitTimer method.

Protected Attributes

pthread_mutex_t event_mutex
pthread_mutex_t control_mutex
sem_t wait_semaphore
pthread_mutex_t timer_mutex
pthread_cond_t timer_condition
pthread_mutex_t waitSemaphoreMutex
pthread_cond_t waitSemaphoreCondition
int waitSemaphoreCounter
double waitDelay

Friends

void * timer_routine (void *arg)
void * run_routine (void *arg)


Member Function Documentation

void POSIX_Simulator::cancelWaitTimer  )  [protected, virtual]
 

Override this method to immediately stop the timer started by the startWaitTimer method.

If you system does not provide such an operation, a clean implementation may be waiting for either a timout or a condition in a separate thread, and this cancel function triggers the condition. Then, by testing which of the timer or condition stopped the waiting, you can either call the timer callback or return immediately.

See also:
startWaitTimer

Reimplemented from Simulator.

void POSIX_Simulator::eventMutexLock  )  [protected, virtual]
 

Override this method to lock the mutex that will be used for event related functions.

The function should block as expected until the mutex is available No locking by default, see CPP.

Reimplemented from Simulator.

double POSIX_Simulator::getSystemTime  )  [virtual]
 

Override this method to return the current system time, expressed in system time units (usually seconds).

Note:
This function is only used for computing differences, so the time origin doesn't matter. This allows you to use system clocks using any time reference mechanism, like the POSIX monotonic high-resolution clocks.
See also:
getTime()

Reimplemented from Simulator.

void POSIX_Simulator::start bool  threaded = true  )  [virtual]
 

Start processing events at a rate determined by the time factor.

This function returns immediately by default, and process the events in another thread. You may change this by setting the argument to false Of course, there is a limit at how fast you can process events, that is how small you can set the time factor for a fixed amount of events, depending on your system performances. Below this value, you'll probably see a large drift between simulated time and system time. In this case, you can gain an extra bit of performance by setting the factor to 0, which means "process the events as fast as possible".

Note:
The default implementation does actually NOT start a thread, but blocks. Threads are system dependant. A helper protected function eventLoop() is provided so you can easily override this class for your particular thread system, if this is not done already.
Parameters:
threaded whether a new thread should be started to process the event loop. Default is true

Reimplemented from Simulator.

void POSIX_Simulator::startWaitTimer double  delay  )  [protected, virtual]
 

Override this method to start some kind of timer, that will call the timer callback provided after the given delay.

The delay is expressed in system time units, so implementations don't need to use the time factor. If your system does not provide timers, an implementation may be to wait in another thread for either some amount of time or some unblocking condition :

See also:
cancelWaitTimer().
Parameters:
delay the time to wait before calling the timer callback, expressed in system time units as used by the getSystemTime method.

Reimplemented from Simulator.

void POSIX_Simulator::stepControlMutexLock  )  [protected, virtual]
 

Override this method to locking the mutex that will be used for controlling the simulation.

Only one thread can call step, or the event loop at the same time. The function should block as expected until the mutex is available No locking by default, see CPP.

Reimplemented from Simulator.

bool POSIX_Simulator::stepControlMutexTryLock  )  [protected, virtual]
 

Override this method to try locking a mutex that will be used for controlling the simulation.

Only one thread can call step, or the event loop at the same time. The function should return true on success, or return immediately false otherwise No locking by default, see CPP.

Reimplemented from Simulator.

void POSIX_Simulator::waitSemaphoreFlush  )  [protected, virtual]
 

Override this method to flush a semaphore that will be used for waiting for a new event in the event loop.

By flushing, we mean that the semaphore count should be zero after this call. This call is done in a protected section such that no post will be done to the semaphore while calling this function. If your system doesn't propose better, you might thus try creating a new semaphore with 0 count.

Reimplemented from Simulator.


The documentation for this class was generated from the following files:
Generated on Mon Mar 28 11:27:42 2005 for Crogai by  doxygen 1.4.1