The Pedigree Project  0.1
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
TimeoutGuard Class Reference

#include <TimeoutGuard.h>

+ Collaboration diagram for TimeoutGuard:

Classes

class  TimeoutGuardEvent
 

Public Member Functions

 TimeoutGuard (size_t timeoutSecs)
 
 ~TimeoutGuard ()
 
bool timedOut ()
 
void cancel () NORETURN
 

Private Member Functions

 TimeoutGuard (const TimeoutGuard &)
 
TimeoutGuardoperator= (const TimeoutGuard &)
 

Private Attributes

TimeoutGuardEventm_pEvent
 
bool m_bTimedOut
 
SchedulerState m_State
 
size_t m_nLevel
 
Spinlock m_Lock
 

Detailed Description

This class waits (in the background) for a given amount of time to elapse, then cancels whatever operation is currently taking place.

The class functions in a similar way to setjmp/longjmp, except using saveState/editState. The timeout is cancelled when the class goes out of scope.

Note
Because it uses 'longjmp', this class can cause memory leaks and skip destructors for stack-local objects. Use it wisely.

Definition at line 45 of file TimeoutGuard.h.

Constructor & Destructor Documentation

TimeoutGuard::TimeoutGuard ( size_t  timeoutSecs)

Creates a new TimeoutGuard, with the given timeout, in seconds.

Definition at line 35 of file TimeoutGuard.cc.

References Timer::addAlarm(), Thread::getStateLevel(), Machine::getTimer(), Processor::information(), m_nLevel, m_pEvent, m_State, Processor::saveState(), and WARNING.

TimeoutGuard::~TimeoutGuard ( )

Destroys the TimeoutGuard, cancelling the timeout.

Definition at line 60 of file TimeoutGuard.cc.

References Machine::getTimer(), Processor::information(), m_Lock, m_pEvent, and Timer::removeAlarm().

Member Function Documentation

void TimeoutGuard::cancel ( )

Cancels the current operation.

Note
This is intended only to be called from a TimeoutGuardEvent.

Definition at line 79 of file TimeoutGuard.cc.

References cancel(), FATAL, m_bTimedOut, m_pEvent, TimeoutGuard::TimeoutGuardEvent::m_pTarget, m_State, NOTICE, and Processor::restoreState().

Referenced by cancel().

+ Here is the caller graph for this function:

bool TimeoutGuard::timedOut ( )
inline

Returns true if the guard just timed out, false if not. This should be called just after the constructor.

Definition at line 56 of file TimeoutGuard.h.

References NORETURN.

Member Data Documentation

bool TimeoutGuard::m_bTimedOut
private

Did the operation time out?

Definition at line 99 of file TimeoutGuard.h.

Referenced by cancel().

Spinlock TimeoutGuard::m_Lock
private

Our own personal lock.

Definition at line 112 of file TimeoutGuard.h.

Referenced by ~TimeoutGuard().

size_t TimeoutGuard::m_nLevel
private

Saved nesting level.

Definition at line 109 of file TimeoutGuard.h.

Referenced by TimeoutGuard().

TimeoutGuardEvent* TimeoutGuard::m_pEvent
private

The event, which will be automatically freed when it fires.

Definition at line 96 of file TimeoutGuard.h.

Referenced by cancel(), TimeoutGuard(), and ~TimeoutGuard().

SchedulerState TimeoutGuard::m_State
private

Saved state.

Definition at line 103 of file TimeoutGuard.h.

Referenced by cancel(), and TimeoutGuard().


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