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 5 // Specializations of RunnableAdapter<> for Windows specific calling 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_ 10 11 #include "build/build_config.h" 12 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 18 namespace base { 19 namespace internal { 20 21 template <typename Functor> 22 class RunnableAdapter; 23 24 // __stdcall Function. 25 template <typename R, typename... Args> 26 class RunnableAdapter<R(__stdcall *)(Args...)> { 27 public: 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...); 31 32 explicit RunnableAdapter(R(__stdcall *function)(Args...)) 33 : function_(function) { 34 } 35 36 R Run(typename CallbackParamTraits<Args>::ForwardType... args) { 37 return function_(args...); 38 } 39 40 private: 41 R (__stdcall *function_)(Args...); 42 }; 43 44 // __fastcall Function. 45 template <typename R, typename... Args> 46 class RunnableAdapter<R(__fastcall *)(Args...)> { 47 public: 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...); 51 52 explicit RunnableAdapter(R(__fastcall *function)(Args...)) 53 : function_(function) { 54 } 55 56 R Run(typename CallbackParamTraits<Args>::ForwardType... args) { 57 return function_(args...); 58 } 59 60 private: 61 R (__fastcall *function_)(Args...); 62 }; 63 64 } // namespace internal 65 } // namespace base 66 67 #endif // !defined(ARCH_CPU_X86_64) 68 69 #endif // BASE_BIND_INTERNAL_WIN_H_ 70