Lunchbox  1.15.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
requestHandler.h
1 
2 /* Copyright (c) 2005-2014, 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 { class RequestHandler; }
29 
44 class RequestHandler : public boost::noncopyable
45 {
46 public:
48  LUNCHBOX_API RequestHandler();
49 
51  LUNCHBOX_API ~RequestHandler();
52 
60  template< class T > Request< T > registerRequest( void* data = 0 );
61 
70  uint32_t registerRequest( void* data = 0 ) { return _register( data ); }
71 
82  LUNCHBOX_API void unregisterRequest( const uint32_t requestID );
83 
98  LUNCHBOX_API bool waitRequest( const uint32_t requestID, void*& result,
99  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
100 
102  LUNCHBOX_API bool waitRequest( const uint32_t requestID, uint32_t& result,
103  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
105  LUNCHBOX_API bool waitRequest( const uint32_t requestID, bool& result,
106  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
108  LUNCHBOX_API bool waitRequest( const uint32_t requestID,
109  servus::uint128_t& result,
110  const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
112  LUNCHBOX_API bool waitRequest( const uint32_t requestID );
113 
121  LUNCHBOX_API void* getRequestData( const uint32_t requestID );
122 
130  LUNCHBOX_API void serveRequest( const uint32_t requestID,
131  void* result = 0 );
133  LUNCHBOX_API void serveRequest( const uint32_t requestID,
134  uint32_t result );
136  LUNCHBOX_API void serveRequest( const uint32_t requestID, bool result );
138  LUNCHBOX_API void serveRequest( const uint32_t requestID,
139  const servus::uint128_t& result );
144  LUNCHBOX_API bool hasPendingRequests() const;
145 
146  LUNCHBOX_API bool isRequestReady( const uint32_t ) const;
147 
148 private:
149  detail::RequestHandler* const _impl;
150  friend LUNCHBOX_API std::ostream& operator << ( std::ostream&,
151  const RequestHandler& );
152  LUNCHBOX_API uint32_t _register( void* data );
153  LB_TS_VAR( _thread );
154 };
155 
156 LUNCHBOX_API std::ostream& operator << ( std::ostream&, const RequestHandler& );
157 }
158 
159 #include <lunchbox/request.h>
160 
161 namespace lunchbox
162 {
163 template< class T > inline
165 {
166  return Request< T >( *this, _register( data ));
167 }
168 }
169 
170 #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:39
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:32
std::ostream & operator<<(std::ostream &os, const Array< T > &array)
Pretty-print all members of the array.
Definition: array.h:47
A thread-safe request handler.
Request< T > registerRequest(void *data=0)
Register a request.