Lunchbox
1.6.0
|
A thread-safe request handler. More...
#include <requestHandler.h>
Public Member Functions | |
RequestHandler () | |
Construct a new request handler. | |
~RequestHandler () | |
Destruct the request handler. | |
uint32_t | registerRequest (void *data=0) |
Register a new request. | |
void | unregisterRequest (const uint32_t requestID) |
Unregister a request. | |
bool | waitRequest (const uint32_t requestID, void *&result, const uint32_t timeout=LB_TIMEOUT_INDEFINITE) |
Wait a given time for the completion of a request. | |
bool | waitRequest (const uint32_t requestID, uint32_t &result, const uint32_t timeout=LB_TIMEOUT_INDEFINITE) |
Wait for a request with an uint32_t result. | |
bool | waitRequest (const uint32_t requestID, bool &result, const uint32_t timeout=LB_TIMEOUT_INDEFINITE) |
Wait for a request with a bool result. | |
bool | waitRequest (const uint32_t requestID, uint128_t &result, const uint32_t timeout=LB_TIMEOUT_INDEFINITE) |
Wait for a request with an uint128_t result. | |
bool | waitRequest (const uint32_t requestID) |
Wait for a request without a result. | |
bool | isRequestServed (const uint32_t requestID) const |
Poll for the completion of a request. | |
void * | getRequestData (const uint32_t requestID) |
Retrieve the user-specific data for a request. | |
void | serveRequest (const uint32_t requestID, void *result=0) |
Serve a request with a void* result. | |
void | serveRequest (const uint32_t requestID, uint32_t result) |
Serve a request with an uint32_t result. | |
void | serveRequest (const uint32_t requestID, bool result) |
Serve a request with a bool result. | |
void | serveRequest (const uint32_t requestID, const uint128_t &result) |
Serve a request with an uint128_t result. | |
bool | hasPendingRequests () const |
Friends | |
std::ostream & | operator<< (std::ostream &, const RequestHandler &) |
A thread-safe request handler.
Different execution threads can synchronize using a request handler. One thread registers a request, and later waits for the request to be served. Another thread can serve the request, providing a result value.
A note on thread-safety: Unless threadSafe is set in the constructor, the functions registerRequest(), unregisterRequest() and waitRequest() are supposed to be called from one 'waiting' thread, and the functions serveRequest() and deleteRequest() are supposed to be called only from one 'serving' thread.
Definition at line 44 of file requestHandler.h.
Construct a new request handler.
Destruct the request handler.
void* lunchbox::RequestHandler::getRequestData | ( | const uint32_t | requestID | ) |
Retrieve the user-specific data for a request.
requestID | the request identifier. |
bool lunchbox::RequestHandler::hasPendingRequests | ( | ) | const |
bool lunchbox::RequestHandler::isRequestServed | ( | const uint32_t | requestID | ) | const |
Poll for the completion of a request.
Does not unregister the request.
requestID | the request identifier. |
uint32_t lunchbox::RequestHandler::registerRequest | ( | void * | data = 0 | ) |
Register a new request.
data | a pointer to user-specific data for the request, can be 0. |
void lunchbox::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
void * | result = 0 |
||
) |
Serve a request with a void* result.
requestID | the request identifier. |
result | the result of the request. |
void lunchbox::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
uint32_t | result | ||
) |
Serve a request with an uint32_t result.
void lunchbox::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
bool | result | ||
) |
Serve a request with a bool result.
void lunchbox::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
const uint128_t & | result | ||
) |
Serve a request with an uint128_t result.
void lunchbox::RequestHandler::unregisterRequest | ( | const uint32_t | requestID | ) |
Unregister a request.
Note that waitRequest automatically unregisters the request when it was successful. This method is only used when a waitRequest has timed out and the request will no longer be used.
requestID | the request identifier. |
bool lunchbox::RequestHandler::waitRequest | ( | const uint32_t | requestID, |
void *& | result, | ||
const uint32_t | timeout = LB_TIMEOUT_INDEFINITE |
||
) |
Wait a given time for the completion of a request.
The request is unregistered upon successful completion, i.e, the when the method returns true.
requestID | the request identifier. |
result | the result code of the operation. |
timeout | the timeout in milliseconds to wait for the request, or LB_TIMEOUT_INDEFINITE to wait indefinitely. |
bool lunchbox::RequestHandler::waitRequest | ( | const uint32_t | requestID, |
uint32_t & | result, | ||
const uint32_t | timeout = LB_TIMEOUT_INDEFINITE |
||
) |
Wait for a request with an uint32_t result.
bool lunchbox::RequestHandler::waitRequest | ( | const uint32_t | requestID, |
bool & | result, | ||
const uint32_t | timeout = LB_TIMEOUT_INDEFINITE |
||
) |
Wait for a request with a bool result.
bool lunchbox::RequestHandler::waitRequest | ( | const uint32_t | requestID, |
uint128_t & | result, | ||
const uint32_t | timeout = LB_TIMEOUT_INDEFINITE |
||
) |
Wait for a request with an uint128_t result.
bool lunchbox::RequestHandler::waitRequest | ( | const uint32_t | requestID | ) |
Wait for a request without a result.