Lunchbox
1.12.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
|
A thread-safe request handler. More...
#include <requestHandler.h>
Public Member Functions | |
LUNCHBOX_API | RequestHandler () |
Construct a new request handler. More... | |
LUNCHBOX_API | ~RequestHandler () |
Destruct the request handler. More... | |
template<class T > | |
Request< T > | registerRequest (void *data=0) |
Register a request. More... | |
uint32_t | registerRequest (void *data=0) |
Register a request. More... | |
LUNCHBOX_API void | unregisterRequest (const uint32_t requestID) |
Unregister a request. More... | |
LUNCHBOX_API 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. More... | |
LUNCHBOX_API 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. More... | |
LUNCHBOX_API bool | waitRequest (const uint32_t requestID, bool &result, const uint32_t timeout=LB_TIMEOUT_INDEFINITE) |
Wait for a request with a bool result. More... | |
LUNCHBOX_API bool | waitRequest (const uint32_t requestID, servus::uint128_t &result, const uint32_t timeout=LB_TIMEOUT_INDEFINITE) |
Wait for a request with an uint128_t result. More... | |
LUNCHBOX_API bool | waitRequest (const uint32_t requestID) |
Wait for a request without a result. More... | |
bool | isRequestServed (const uint32_t id) const LB_DEPRECATED |
Poll for the completion of a request. More... | |
LUNCHBOX_API void * | getRequestData (const uint32_t requestID) |
Retrieve the user-specific data for a request. More... | |
LUNCHBOX_API void | serveRequest (const uint32_t requestID, void *result=0) |
Serve a request with a void* result. More... | |
LUNCHBOX_API void | serveRequest (const uint32_t requestID, uint32_t result) |
Serve a request with an uint32_t result. More... | |
LUNCHBOX_API void | serveRequest (const uint32_t requestID, bool result) |
Serve a request with a bool result. More... | |
LUNCHBOX_API void | serveRequest (const uint32_t requestID, const servus::uint128_t &result) |
Serve a request with an uint128_t result. More... | |
LUNCHBOX_API bool | hasPendingRequests () const |
LUNCHBOX_API bool | isRequestReady (const uint32_t) const |
Friends | |
LUNCHBOX_API 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.
Thread-safety: The methods 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.
Example:
Definition at line 44 of file requestHandler.h.
LUNCHBOX_API lunchbox::RequestHandler::RequestHandler | ( | ) |
Construct a new request handler.
LUNCHBOX_API lunchbox::RequestHandler::~RequestHandler | ( | ) |
Destruct the request handler.
LUNCHBOX_API void* lunchbox::RequestHandler::getRequestData | ( | const uint32_t | requestID | ) |
Retrieve the user-specific data for a request.
requestID | the request identifier. |
LUNCHBOX_API bool lunchbox::RequestHandler::hasPendingRequests | ( | ) | const |
|
inline |
|
inline |
Register a request.
data | a pointer to user-specific data for the request, can be 0. |
Definition at line 173 of file requestHandler.h.
|
inline |
Register a request.
data | a pointer to user-specific data for the request, can be 0. |
Definition at line 70 of file requestHandler.h.
LUNCHBOX_API 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. |
LUNCHBOX_API void lunchbox::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
uint32_t | result | ||
) |
Serve a request with an uint32_t result.
LUNCHBOX_API void lunchbox::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
bool | result | ||
) |
Serve a request with a bool result.
LUNCHBOX_API void lunchbox::RequestHandler::serveRequest | ( | const uint32_t | requestID, |
const servus::uint128_t & | result | ||
) |
Serve a request with an uint128_t result.
LUNCHBOX_API 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. |
LUNCHBOX_API 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. |
Referenced by lunchbox::Request< T >::Impl::wait().
LUNCHBOX_API 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.
LUNCHBOX_API 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.
LUNCHBOX_API bool lunchbox::RequestHandler::waitRequest | ( | const uint32_t | requestID, |
servus::uint128_t & | result, | ||
const uint32_t | timeout = LB_TIMEOUT_INDEFINITE |
||
) |
Wait for a request with an uint128_t result.
LUNCHBOX_API bool lunchbox::RequestHandler::waitRequest | ( | const uint32_t | requestID | ) |
Wait for a request without a result.