The Pedigree Project  0.1
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
RequestQueue Class Referenceabstract

#include <RequestQueue.h>

+ Inheritance diagram for RequestQueue:
+ Collaboration diagram for RequestQueue:

Classes

class  Request
 
class  RequestQueueOverrunChecker
 

Public Types

enum  ActionOnDuplicate { Block, NewRequest, ReturnImmediately }
 

Public Member Functions

 RequestQueue (const String &name)
 
virtual void initialise ()
 
virtual void destroy ()
 
MUST_USE_RESULT uint64_t addRequest (size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0)
 
MUST_USE_RESULT uint64_t addRequest (size_t priority, ActionOnDuplicate action, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0)
 
uint64_t addAsyncRequest (size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0)
 
void halt ()
 
void resume ()
 

Protected Member Functions

virtual uint64_t executeRequest (uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5, uint64_t p6, uint64_t p7, uint64_t p8)=0
 
 RequestQueue (const RequestQueue &)
 
void operator= (const RequestQueue &)
 
virtual bool compareRequests (const Request &a, const Request &b)
 
bool isRequestValid (const Request *r)
 
int work ()
 
RequestgetNextRequest ()
 

Static Protected Member Functions

static int trampoline (void *p)
 
static int doAsync (void *p)
 

Protected Attributes

Requestm_pRequestQueue [REQUEST_QUEUE_NUM_PRIORITIES]
 
volatile bool m_Stop
 
Mutex m_RequestQueueMutex
 
ConditionVariable m_RequestQueueCondition
 
ConditionVariable m_AsyncRequestQueueCondition
 
Threadm_pThread
 
bool m_Halted
 
Mutex m_HaltAcknowledged
 
RequestQueueOverrunChecker m_OverrunChecker
 
size_t m_nMaxAsyncRequests
 
size_t m_nAsyncRequests
 
size_t m_nTotalRequests
 
String m_Name
 

Friends

class Thread
 

Detailed Description

Implements a request queue, with one worker thread performing all requests. All requests appear synchronous to the calling thread - calling threads are blocked on mutexes (so they can be put to sleep) until their request is complete.

Definition at line 41 of file RequestQueue.h.

Constructor & Destructor Documentation

RequestQueue::RequestQueue ( const String name)

Creates a new RequestQueue.

Definition at line 35 of file RequestQueue.cc.

References destroy(), and m_pRequestQueue.

Member Function Documentation

uint64_t RequestQueue::addAsyncRequest ( size_t  priority,
uint64_t  p1 = 0,
uint64_t  p2 = 0,
uint64_t  p3 = 0,
uint64_t  p4 = 0,
uint64_t  p5 = 0,
uint64_t  p6 = 0,
uint64_t  p7 = 0,
uint64_t  p8 = 0 
)

Adds an asynchronous request to the queue. Will not block.

Definition at line 282 of file RequestQueue.cc.

References addRequest(), Thread::detach(), doAsync(), ERROR, Hex, and Scheduler::instance().

Referenced by ScsiDisk::read(), Cache::release(), Cache::sync(), Cache::timer(), and ScsiDisk::write().

+ Here is the caller graph for this function:

uint64_t RequestQueue::addRequest ( size_t  priority,
uint64_t  p1 = 0,
uint64_t  p2 = 0,
uint64_t  p3 = 0,
uint64_t  p4 = 0,
uint64_t  p5 = 0,
uint64_t  p6 = 0,
uint64_t  p7 = 0,
uint64_t  p8 = 0 
)

Adds a request to the queue. Blocks until it finishes and returns the result.

Parameters
priorityThe priority to attach to this request. Lower number is higher priority.

Definition at line 118 of file RequestQueue.cc.

Referenced by addAsyncRequest(), doAsync(), ScsiDisk::flush(), ScsiDisk::read(), and Cache::sync().

+ Here is the caller graph for this function:

uint64_t RequestQueue::addRequest ( size_t  priority,
ActionOnDuplicate  action,
uint64_t  p1 = 0,
uint64_t  p2 = 0,
uint64_t  p3 = 0,
uint64_t  p4 = 0,
uint64_t  p5 = 0,
uint64_t  p6 = 0,
uint64_t  p7 = 0,
uint64_t  p8 = 0 
)
virtual bool RequestQueue::compareRequests ( const Request a,
const Request b 
)
inlineprotectedvirtual

Defaults to never comparing as equal. Used to determine duplicates when adding async requests.

Reimplemented in CacheManager, and AtaController.

Definition at line 166 of file RequestQueue.h.

Referenced by addRequest().

+ Here is the caller graph for this function:

void RequestQueue::destroy ( )
virtual

Destroys the queue, killing the worker thread (safely)

Definition at line 85 of file RequestQueue.cc.

References Semaphore::acquire(), Machine::getTimer(), halt(), m_pRequestQueue, m_RequestQueueMutex, and Semaphore::release().

Referenced by RequestQueue().

+ Here is the caller graph for this function:

int RequestQueue::doAsync ( void *  p)
staticprotected

Asynchronous thread trampoline

Definition at line 262 of file RequestQueue.cc.

References addRequest().

Referenced by addAsyncRequest().

+ Here is the caller graph for this function:

virtual uint64_t RequestQueue::executeRequest ( uint64_t  p1,
uint64_t  p2,
uint64_t  p3,
uint64_t  p4,
uint64_t  p5,
uint64_t  p6,
uint64_t  p7,
uint64_t  p8 
)
protectedpure virtual

Callback - classes are expected to inherit and override this function. It's called when a request needs to be executed (by the worker thread).

Implemented in Ohci, Ehci, Uhci, NetworkStack, CacheManager, ZombieQueue, PciAtaController, IsaAtaController, and ScsiController.

Referenced by addRequest(), and work().

+ Here is the caller graph for this function:

RequestQueue::Request * RequestQueue::getNextRequest ( )
protected

Get the next Request, or NULL if no available requests.

Todo:
Stop possible starvation here.

Definition at line 373 of file RequestQueue.cc.

References assert, Semaphore::getValue(), m_pRequestQueue, and m_RequestQueueMutex.

Referenced by work().

+ Here is the caller graph for this function:

void RequestQueue::halt ( )

Halt RequestQueue operations, but do not terminate the worker thread.

Definition at line 333 of file RequestQueue.cc.

References Semaphore::acquire(), ConditionVariable::broadcast(), Thread::join(), m_RequestQueueCondition, m_RequestQueueMutex, m_Stop, and Semaphore::release().

Referenced by destroy(), and Thread::shutdown().

+ Here is the caller graph for this function:

void RequestQueue::initialise ( )
virtual

Initialises the queue, spawning the worker thread.

Reimplemented in CacheManager.

Definition at line 55 of file RequestQueue.cc.

References Machine::getTimer(), Scheduler::instance(), m_Stop, trampoline(), and WARNING.

Referenced by CacheManager::initialise(), PciAtaController::PciAtaController(), and resume().

+ Here is the caller graph for this function:

bool RequestQueue::isRequestValid ( const Request r)
protected

Check whether the given request is still valid in terms of this RequestQueue.

Definition at line 520 of file RequestQueue.cc.

References m_pRequestQueue, and m_RequestQueueMutex.

Referenced by Thread::shutdown().

+ Here is the caller graph for this function:

void RequestQueue::resume ( )

Resume RequestQueue operations.

Definition at line 355 of file RequestQueue.cc.

References initialise(), and m_RequestQueueMutex.

Referenced by Thread::shutdown().

+ Here is the caller graph for this function:

int RequestQueue::trampoline ( void *  p)
staticprotected

Thread trampoline

Definition at line 367 of file RequestQueue.cc.

References work().

Referenced by initialise().

+ Here is the caller graph for this function:

int RequestQueue::work ( )
protected

Member Data Documentation

ConditionVariable RequestQueue::m_AsyncRequestQueueCondition
protected

Condition variable for verifying if we can do an async request.

Definition at line 203 of file RequestQueue.h.

Request* RequestQueue::m_pRequestQueue[REQUEST_QUEUE_NUM_PRIORITIES]
protected

The request queue

Definition at line 190 of file RequestQueue.h.

Referenced by addRequest(), destroy(), getNextRequest(), isRequestValid(), and RequestQueue().

ConditionVariable RequestQueue::m_RequestQueueCondition
protected

Condition variable for verifying if items exist.

Definition at line 200 of file RequestQueue.h.

Referenced by addRequest(), halt(), and work().

Mutex RequestQueue::m_RequestQueueMutex
protected

Mutex to be held when the request queue is being changed.

Definition at line 197 of file RequestQueue.h.

Referenced by addRequest(), destroy(), getNextRequest(), halt(), isRequestValid(), resume(), and work().

volatile bool RequestQueue::m_Stop
protected

True if the worker thread should cleanup and stop.

Definition at line 193 of file RequestQueue.h.

Referenced by halt(), initialise(), and work().


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