|
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) LB_DEPRECATED |
| 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, 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 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 |
|
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:
#ifdef WARN_DEPRECATED
# undef WARN_DEPRECATED
#endif
#include "test.h"
#include <lunchbox/mtQueue.h>
#include <lunchbox/requestHandler.h>
#include <lunchbox/sleep.h>
#include <lunchbox/thread.h>
#include <lunchbox/uint128_t.h>
{
public:
virtual void run() final
{
const bool boolIn = true;
uint8_t* payload = (uint8_t*)42;
uint32_t request = requestQ_.
pop();
const uint32_t uint32In = 0xC0FFEE;
request = requestQ_.
pop();
request = requestQ_.
pop();
request = requestQ_.
pop();
request );
request = requestQ_.
pop();
}
};
int main( int, char** )
{
uint8_t* payload = (uint8_t*)42;
Thread thread;
thread.start();
requestQ_.
push( request );
bool boolOut = false;
TEST( boolOut == true );
requestQ_.
push( request );
requestQ_.
push( voidFuture.getID( ));
requestQ_.
push( uint128Future.getID( ));
TEST( future.
wait( ) == 0xC0FFEE );
TEST( uint128Future.wait() == uuid );
TEST( thread.join( ));
return EXIT_SUCCESS;
}
Definition at line 43 of file requestHandler.h.