Lunchbox  1.17.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
requestHandler.h
1 
2 /* Copyright (c) 2005-2017, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #ifndef LUNCHBOX_REQUESTHANDLER_H
19 #define LUNCHBOX_REQUESTHANDLER_H
20 
21 #include <lunchbox/api.h> // LUNCHBOX_API definition
22 #include <lunchbox/thread.h> // thread-safety macros
23 #include <lunchbox/types.h>
24 #include <servus/uint128_t.h>
25 
26 namespace lunchbox
27 {
28 namespace detail
29 {
30 class RequestHandler;
31 }
32 
47 class RequestHandler : public boost::noncopyable
48 {
49 public:
51  LUNCHBOX_API RequestHandler();
52 
54  LUNCHBOX_API ~RequestHandler();
55 
63  template <class T>
64  Request<T> registerRequest(void* data = 0);
65 
74  uint32_t registerRequest(void* data = 0) { return _register(data); }
85  LUNCHBOX_API void unregisterRequest(const uint32_t requestID);
86 
101  LUNCHBOX_API bool waitRequest(
102  const uint32_t requestID, void*& result,
103  const uint32_t timeout = LB_TIMEOUT_INDEFINITE);
104 
106  LUNCHBOX_API bool waitRequest(
107  const uint32_t requestID, uint32_t& result,
108  const uint32_t timeout = LB_TIMEOUT_INDEFINITE);
110  LUNCHBOX_API bool waitRequest(
111  const uint32_t requestID, bool& result,
112  const uint32_t timeout = LB_TIMEOUT_INDEFINITE);
114  LUNCHBOX_API bool waitRequest(
115  const uint32_t requestID, servus::uint128_t& result,
116  const uint32_t timeout = LB_TIMEOUT_INDEFINITE);
118  LUNCHBOX_API bool waitRequest(const uint32_t requestID);
119 
127  LUNCHBOX_API void* getRequestData(const uint32_t requestID);
128 
136  LUNCHBOX_API void serveRequest(const uint32_t requestID, void* result = 0);
138  LUNCHBOX_API void serveRequest(const uint32_t requestID, uint32_t result);
140  LUNCHBOX_API void serveRequest(const uint32_t requestID, bool result);
142  LUNCHBOX_API void serveRequest(const uint32_t requestID,
143  const servus::uint128_t& result);
148  LUNCHBOX_API bool hasPendingRequests() const;
149 
150  LUNCHBOX_API bool isRequestReady(const uint32_t) const;
151 
152 private:
153  detail::RequestHandler* const _impl;
154 
155  LUNCHBOX_API uint32_t _register(void* data);
156  LB_TS_VAR(_thread);
157 };
158 }
159 
160 #include <lunchbox/request.h>
161 
162 namespace lunchbox
163 {
164 template <class T>
166 {
167  return Request<T>(*this, _register(data));
168 }
169 }
170 
171 #endif // LUNCHBOX_REQUESTHANDLER_H
Defines export visibility macros for library Lunchbox.
Basic type definitions not provided by the operating system.
uint32_t registerRequest(void *data=0)
Register a request.
#define LB_TIMEOUT_INDEFINITE
Constant defining &#39;wait forever&#39; in methods with wait parameters.
Definition: types.h:80
A Future implementation for a RequestHandler request.
Definition: request.h:41
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:29
A thread-safe request handler.
Request< T > registerRequest(void *data=0)
Register a request.