[email protected] | 054ac754 | 2011-02-27 01:25:59 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 5 | // Specializations of RunnableAdapter<> for Windows specific calling |
[email protected] | 054ac754 | 2011-02-27 01:25:59 | [diff] [blame] | 6 | // conventions. Please see base/bind_internal.h for more info. |
7 | |||||
8 | #ifndef BASE_BIND_INTERNAL_WIN_H_ | ||||
9 | #define BASE_BIND_INTERNAL_WIN_H_ | ||||
[email protected] | 054ac754 | 2011-02-27 01:25:59 | [diff] [blame] | 10 | |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 11 | #include "build/build_config.h" |
12 | |||||
[email protected] | b224f79 | 2011-04-20 16:02:23 | [diff] [blame] | 13 | // In the x64 architecture in Windows, __fastcall, __stdcall, etc, are all |
14 | // the same as __cdecl which would turn the following specializations into | ||||
15 | // multiple definitions. | ||||
16 | #if !defined(ARCH_CPU_X86_64) | ||||
17 | |||||
[email protected] | 054ac754 | 2011-02-27 01:25:59 | [diff] [blame] | 18 | namespace base { |
19 | namespace internal { | ||||
20 | |||||
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 21 | template <typename Functor> |
22 | class RunnableAdapter; | ||||
[email protected] | 054ac754 | 2011-02-27 01:25:59 | [diff] [blame] | 23 | |
tzik | a0125aec | 2014-10-07 20:03:54 | [diff] [blame] | 24 | // __stdcall Function. |
25 | template <typename R, typename... Args> | ||||
26 | class RunnableAdapter<R(__stdcall *)(Args...)> { | ||||
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 27 | public: |
tzik | 3bc7779b | 2015-12-19 09:18:46 | [diff] [blame] | 28 | // MSVC 2013 doesn't support Type Alias of function types. |
29 | // Revisit this after we update it to newer version. | ||||
30 | typedef R RunType(Args...); | ||||
[email protected] | 9354058 | 2011-05-16 22:35:14 | [diff] [blame] | 31 | |
tzik | a0125aec | 2014-10-07 20:03:54 | [diff] [blame] | 32 | explicit RunnableAdapter(R(__stdcall *function)(Args...)) |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 33 | : function_(function) { |
34 | } | ||||
35 | |||||
tzik | a0125aec | 2014-10-07 20:03:54 | [diff] [blame] | 36 | R Run(typename CallbackParamTraits<Args>::ForwardType... args) { |
37 | return function_(args...); | ||||
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 38 | } |
39 | |||||
40 | private: | ||||
tzik | a0125aec | 2014-10-07 20:03:54 | [diff] [blame] | 41 | R (__stdcall *function_)(Args...); |
[email protected] | 054ac754 | 2011-02-27 01:25:59 | [diff] [blame] | 42 | }; |
43 | |||||
tzik | a0125aec | 2014-10-07 20:03:54 | [diff] [blame] | 44 | // __fastcall Function. |
45 | template <typename R, typename... Args> | ||||
46 | class RunnableAdapter<R(__fastcall *)(Args...)> { | ||||
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 47 | public: |
tzik | 3bc7779b | 2015-12-19 09:18:46 | [diff] [blame] | 48 | // MSVC 2013 doesn't support Type Alias of function types. |
49 | // Revisit this after we update it to newer version. | ||||
50 | typedef R RunType(Args...); | ||||
[email protected] | 9354058 | 2011-05-16 22:35:14 | [diff] [blame] | 51 | |
tzik | a0125aec | 2014-10-07 20:03:54 | [diff] [blame] | 52 | explicit RunnableAdapter(R(__fastcall *function)(Args...)) |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 53 | : function_(function) { |
54 | } | ||||
55 | |||||
tzik | a0125aec | 2014-10-07 20:03:54 | [diff] [blame] | 56 | R Run(typename CallbackParamTraits<Args>::ForwardType... args) { |
57 | return function_(args...); | ||||
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 58 | } |
59 | |||||
60 | private: | ||||
tzik | a0125aec | 2014-10-07 20:03:54 | [diff] [blame] | 61 | R (__fastcall *function_)(Args...); |
[email protected] | fccef155 | 2011-11-28 22:13:54 | [diff] [blame] | 62 | }; |
63 | |||||
[email protected] | 054ac754 | 2011-02-27 01:25:59 | [diff] [blame] | 64 | } // namespace internal |
65 | } // namespace base | ||||
66 | |||||
[email protected] | b224f79 | 2011-04-20 16:02:23 | [diff] [blame] | 67 | #endif // !defined(ARCH_CPU_X86_64) |
68 | |||||
[email protected] | 054ac754 | 2011-02-27 01:25:59 | [diff] [blame] | 69 | #endif // BASE_BIND_INTERNAL_WIN_H_ |