1 | // (C) Copyright Mac Murrett 2001. |
---|
2 | // Use, modification and distribution are subject to the |
---|
3 | // Boost Software License, Version 1.0. (See accompanying file |
---|
4 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | |
---|
6 | // See http://www.boost.org for most recent version. |
---|
7 | |
---|
8 | #ifndef BOOST_REMOTE_CALLS_MJM012402_HPP |
---|
9 | #define BOOST_REMOTE_CALLS_MJM012402_HPP |
---|
10 | |
---|
11 | |
---|
12 | #include <boost/bind.hpp> |
---|
13 | |
---|
14 | #include "remote_call_manager.hpp" |
---|
15 | #include <boost/thread/detail/singleton.hpp> |
---|
16 | |
---|
17 | |
---|
18 | // this file contains macros to generate functions with the signatures: |
---|
19 | // ReturnType st_remote_call([pascal] ReturnType (*pfnFunction)( |
---|
20 | // [Argument1Type[, Argument2Type[...]]]) |
---|
21 | // [, Argument1Type oArgument1[, Argument2Type oArgument2[...]]]) |
---|
22 | // and |
---|
23 | // ReturnType dt_remote_call([pascal] ReturnType (*pfnFunction)( |
---|
24 | // [Argument1Type[, Argument2Type[...]]]) |
---|
25 | // [, Argument1Type oArgument1[, Argument2Type oArgument2[...]]]) |
---|
26 | // in other words, identical to the function pointer versions of boost::bind, but |
---|
27 | // with the return type returned. The purpose of these functions is to be able to |
---|
28 | // request that a function be called at system task time or deferred task time, then |
---|
29 | // sleep until it is called, and finally get back its return value. |
---|
30 | |
---|
31 | #define BOOST_REMOTE_CALL_CLASS_LIST_0 |
---|
32 | #define BOOST_REMOTE_CALL_CLASS_LIST_1 BOOST_REMOTE_CALL_CLASS_LIST_0, class A1 |
---|
33 | #define BOOST_REMOTE_CALL_CLASS_LIST_2 BOOST_REMOTE_CALL_CLASS_LIST_1, class A2 |
---|
34 | #define BOOST_REMOTE_CALL_CLASS_LIST_3 BOOST_REMOTE_CALL_CLASS_LIST_2, class A3 |
---|
35 | #define BOOST_REMOTE_CALL_CLASS_LIST_4 BOOST_REMOTE_CALL_CLASS_LIST_3, class A4 |
---|
36 | #define BOOST_REMOTE_CALL_CLASS_LIST_5 BOOST_REMOTE_CALL_CLASS_LIST_4, class A5 |
---|
37 | #define BOOST_REMOTE_CALL_CLASS_LIST_6 BOOST_REMOTE_CALL_CLASS_LIST_5, class A6 |
---|
38 | #define BOOST_REMOTE_CALL_CLASS_LIST_7 BOOST_REMOTE_CALL_CLASS_LIST_6, class A7 |
---|
39 | #define BOOST_REMOTE_CALL_CLASS_LIST_8 BOOST_REMOTE_CALL_CLASS_LIST_7, class A8 |
---|
40 | #define BOOST_REMOTE_CALL_CLASS_LIST_9 BOOST_REMOTE_CALL_CLASS_LIST_8, class A9 |
---|
41 | |
---|
42 | |
---|
43 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_0 |
---|
44 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_1 BOOST_REMOTE_CALL_ARGUMENT_LIST_0 A1 oA1 |
---|
45 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_2 BOOST_REMOTE_CALL_ARGUMENT_LIST_1, A2 oA2 |
---|
46 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_3 BOOST_REMOTE_CALL_ARGUMENT_LIST_2, A3 oA3 |
---|
47 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_4 BOOST_REMOTE_CALL_ARGUMENT_LIST_3, A4 oA4 |
---|
48 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_5 BOOST_REMOTE_CALL_ARGUMENT_LIST_4, A5 oA5 |
---|
49 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_6 BOOST_REMOTE_CALL_ARGUMENT_LIST_5, A6 oA6 |
---|
50 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_7 BOOST_REMOTE_CALL_ARGUMENT_LIST_6, A7 oA7 |
---|
51 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_8 BOOST_REMOTE_CALL_ARGUMENT_LIST_7, A8 oA8 |
---|
52 | #define BOOST_REMOTE_CALL_ARGUMENT_LIST_9 BOOST_REMOTE_CALL_ARGUMENT_LIST_8, A9 oA9 |
---|
53 | |
---|
54 | |
---|
55 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_0 |
---|
56 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_1 BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_0, oA1 |
---|
57 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_2 BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_1, oA2 |
---|
58 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_3 BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_2, oA3 |
---|
59 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_4 BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_3, oA4 |
---|
60 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_5 BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_4, oA5 |
---|
61 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_6 BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_5, oA6 |
---|
62 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_7 BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_6, oA7 |
---|
63 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_8 BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_7, oA8 |
---|
64 | #define BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_9 BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_8, oA9 |
---|
65 | |
---|
66 | |
---|
67 | #define BOOST_REMOTE_CALL_COMMA_0 |
---|
68 | #define BOOST_REMOTE_CALL_COMMA_1 , |
---|
69 | #define BOOST_REMOTE_CALL_COMMA_2 , |
---|
70 | #define BOOST_REMOTE_CALL_COMMA_3 , |
---|
71 | #define BOOST_REMOTE_CALL_COMMA_4 , |
---|
72 | #define BOOST_REMOTE_CALL_COMMA_5 , |
---|
73 | #define BOOST_REMOTE_CALL_COMMA_6 , |
---|
74 | #define BOOST_REMOTE_CALL_COMMA_7 , |
---|
75 | #define BOOST_REMOTE_CALL_COMMA_8 , |
---|
76 | #define BOOST_REMOTE_CALL_COMMA_9 , |
---|
77 | |
---|
78 | |
---|
79 | // this is the macro that ties it all together. From here, we generate all forms of |
---|
80 | // dt_remote_call and st_remote_call. |
---|
81 | |
---|
82 | #define BOOST_REMOTE_CALL(context, stack, n) \ |
---|
83 | template<class R BOOST_REMOTE_CALL_CLASS_LIST_ ## n> \ |
---|
84 | inline R context ## _remote_call(stack R (*pfnF)( \ |
---|
85 | BOOST_REMOTE_CALL_ARGUMENT_LIST_ ## n) \ |
---|
86 | BOOST_REMOTE_CALL_COMMA_ ## n \ |
---|
87 | BOOST_REMOTE_CALL_ARGUMENT_LIST_ ## n) \ |
---|
88 | { \ |
---|
89 | using ::boost::detail::thread::singleton; \ |
---|
90 | using detail::remote_call_manager; \ |
---|
91 | function<R> oFunc(bind(pfnF BOOST_REMOTE_CALL_FUNCTION_ARGUMENT_LIST_ ## n)); \ |
---|
92 | remote_call_manager &rManager(singleton<remote_call_manager>::instance()); \ |
---|
93 | return(rManager.execute_at_ ## context(oFunc)); \ |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | namespace boost { |
---|
98 | |
---|
99 | namespace threads { |
---|
100 | |
---|
101 | namespace mac { |
---|
102 | |
---|
103 | |
---|
104 | BOOST_REMOTE_CALL(st, , 0) |
---|
105 | BOOST_REMOTE_CALL(st, , 1) |
---|
106 | BOOST_REMOTE_CALL(st, , 2) |
---|
107 | BOOST_REMOTE_CALL(st, , 3) |
---|
108 | BOOST_REMOTE_CALL(st, , 4) |
---|
109 | BOOST_REMOTE_CALL(st, , 5) |
---|
110 | BOOST_REMOTE_CALL(st, , 6) |
---|
111 | BOOST_REMOTE_CALL(st, , 7) |
---|
112 | BOOST_REMOTE_CALL(st, , 8) |
---|
113 | BOOST_REMOTE_CALL(st, , 9) |
---|
114 | |
---|
115 | BOOST_REMOTE_CALL(dt, , 0) |
---|
116 | BOOST_REMOTE_CALL(dt, , 1) |
---|
117 | BOOST_REMOTE_CALL(dt, , 2) |
---|
118 | BOOST_REMOTE_CALL(dt, , 3) |
---|
119 | BOOST_REMOTE_CALL(dt, , 4) |
---|
120 | BOOST_REMOTE_CALL(dt, , 5) |
---|
121 | BOOST_REMOTE_CALL(dt, , 6) |
---|
122 | BOOST_REMOTE_CALL(dt, , 7) |
---|
123 | BOOST_REMOTE_CALL(dt, , 8) |
---|
124 | BOOST_REMOTE_CALL(dt, , 9) |
---|
125 | |
---|
126 | |
---|
127 | BOOST_REMOTE_CALL(st, pascal, 0) |
---|
128 | BOOST_REMOTE_CALL(st, pascal, 1) |
---|
129 | BOOST_REMOTE_CALL(st, pascal, 2) |
---|
130 | BOOST_REMOTE_CALL(st, pascal, 3) |
---|
131 | BOOST_REMOTE_CALL(st, pascal, 4) |
---|
132 | BOOST_REMOTE_CALL(st, pascal, 5) |
---|
133 | BOOST_REMOTE_CALL(st, pascal, 6) |
---|
134 | BOOST_REMOTE_CALL(st, pascal, 7) |
---|
135 | BOOST_REMOTE_CALL(st, pascal, 8) |
---|
136 | BOOST_REMOTE_CALL(st, pascal, 9) |
---|
137 | |
---|
138 | BOOST_REMOTE_CALL(dt, pascal, 0) |
---|
139 | BOOST_REMOTE_CALL(dt, pascal, 1) |
---|
140 | BOOST_REMOTE_CALL(dt, pascal, 2) |
---|
141 | BOOST_REMOTE_CALL(dt, pascal, 3) |
---|
142 | BOOST_REMOTE_CALL(dt, pascal, 4) |
---|
143 | BOOST_REMOTE_CALL(dt, pascal, 5) |
---|
144 | BOOST_REMOTE_CALL(dt, pascal, 6) |
---|
145 | BOOST_REMOTE_CALL(dt, pascal, 7) |
---|
146 | BOOST_REMOTE_CALL(dt, pascal, 8) |
---|
147 | BOOST_REMOTE_CALL(dt, pascal, 9) |
---|
148 | |
---|
149 | |
---|
150 | } // namespace mac |
---|
151 | |
---|
152 | } // namespace threads |
---|
153 | |
---|
154 | } // namespace boost |
---|
155 | |
---|
156 | |
---|
157 | #endif // BOOST_REMOTE_CALLS_MJM012402_HPP |
---|