@@ -32,7 +32,7 @@ private static int DoDelegateReversePInvokeNonBlittable(bool b)
3232 public static int BlittablePInvokeToBlittableInteropDelegate ( )
3333 {
3434 InteropDelegate del = DoDelegateReversePInvoke ;
35-
35+
3636 DoPInvoke ( ( delegate * unmanaged< int , int > ) Marshal . GetFunctionPointerForDelegate ( del ) , 13 ) ;
3737 GC . KeepAlive ( del ) ;
3838
@@ -42,13 +42,23 @@ public static int BlittablePInvokeToBlittableInteropDelegate()
4242 public static int NonBlittablePInvokeToNonBlittableInteropDelegate ( )
4343 {
4444 InteropDelegateNonBlittable del = DoDelegateReversePInvokeNonBlittable ;
45-
45+
4646 DoPInvokeNonBlitable ( ( delegate * unmanaged< int , int > ) Marshal . GetFunctionPointerForDelegate ( del ) , true ) ;
4747 GC . KeepAlive ( del ) ;
4848
4949 return 100 ;
5050 }
5151
52+ public static int BlittablePInvokeToBlittableInteropDelegateOnOtherThread ( )
53+ {
54+ InteropDelegate del = DoDelegateReversePInvoke ;
55+
56+ DoPInvokeWithCallbackOnOtherThread ( ( delegate * unmanaged< int , int > ) Marshal . GetFunctionPointerForDelegate ( del ) , 13 ) ;
57+ GC . KeepAlive ( del ) ;
58+
59+ return 100 ;
60+ }
61+
5262 [ UnmanagedCallersOnly ]
5363 private static int DoReversePInvoke ( int i )
5464 {
@@ -61,6 +71,9 @@ private static int DoReversePInvoke(int i)
6171 [ DllImport ( "Profiler" , EntryPoint = nameof ( DoPInvoke ) ) ]
6272 public static extern void DoPInvokeNonBlitable ( delegate * unmanaged< int , int > callback , bool i ) ;
6373
74+ [ DllImport ( "Profiler" ) ]
75+ public static extern void DoPInvokeWithCallbackOnOtherThread ( delegate * unmanaged< int , int > callback , int i ) ;
76+
6477 public static int BlittablePInvokeToUnmanagedCallersOnly ( )
6578 {
6679 DoPInvoke ( & DoReversePInvoke , 13 ) ;
@@ -75,6 +88,13 @@ public static int NonBlittablePInvokeToUnmanagedCallersOnly()
7588 return 100 ;
7689 }
7790
91+ public static int BlittablePInvokeToUnmanagedCallersOnlyOnOtherThread ( )
92+ {
93+ DoPInvokeWithCallbackOnOtherThread ( & DoReversePInvoke , 13 ) ;
94+
95+ return 100 ;
96+ }
97+
7898 public static int Main ( string [ ] args )
7999 {
80100 if ( args . Length > 1 && args [ 0 ] . Equals ( "RunTest" , StringComparison . OrdinalIgnoreCase ) )
@@ -89,6 +109,10 @@ public static int Main(string[] args)
89109 return NonBlittablePInvokeToUnmanagedCallersOnly ( ) ;
90110 case nameof ( NonBlittablePInvokeToNonBlittableInteropDelegate ) :
91111 return NonBlittablePInvokeToNonBlittableInteropDelegate ( ) ;
112+ case nameof ( BlittablePInvokeToUnmanagedCallersOnlyOnOtherThread ) :
113+ return BlittablePInvokeToUnmanagedCallersOnlyOnOtherThread ( ) ;
114+ case nameof ( BlittablePInvokeToBlittableInteropDelegateOnOtherThread ) :
115+ return BlittablePInvokeToBlittableInteropDelegateOnOtherThread ( ) ;
92116 }
93117 }
94118
@@ -104,12 +128,22 @@ public static int Main(string[] args)
104128
105129 if ( ! RunProfilerTest ( nameof ( NonBlittablePInvokeToUnmanagedCallersOnly ) , nameof ( DoPInvokeNonBlitable ) , nameof ( DoReversePInvoke ) ) )
106130 {
107- return 101 ;
131+ return 103 ;
108132 }
109133
110134 if ( ! RunProfilerTest ( nameof ( NonBlittablePInvokeToNonBlittableInteropDelegate ) , nameof ( DoPInvokeNonBlitable ) , "Invoke" ) )
111135 {
112- return 102 ;
136+ return 104 ;
137+ }
138+
139+ if ( ! RunProfilerTest ( nameof ( BlittablePInvokeToUnmanagedCallersOnlyOnOtherThread ) , nameof ( DoPInvokeWithCallbackOnOtherThread ) , nameof ( DoReversePInvoke ) ) )
140+ {
141+ return 105 ;
142+ }
143+
144+ if ( ! RunProfilerTest ( nameof ( BlittablePInvokeToBlittableInteropDelegateOnOtherThread ) , nameof ( DoPInvokeWithCallbackOnOtherThread ) , "Invoke" ) )
145+ {
146+ return 106 ;
113147 }
114148
115149 return 100 ;
0 commit comments