File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- using System ;
2- using Python . Runtime ;
1+ using System . Runtime . CompilerServices ;
32
43namespace PythonNETExtensions . Core
54{
6- public readonly struct LongRunningCSharpRegion : IDisposable
5+ public readonly ref struct LongRunningCSharpRegion
76 {
8- private readonly nint Handle ;
7+ private readonly ref PythonHandle Handle ;
98
9+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1010 public LongRunningCSharpRegion ( )
1111 {
12- Handle = PythonEngine . BeginAllowThreads ( ) ;
12+ Handle . Dispose ( ) ;
1313 }
1414
15+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1516 public void Dispose ( )
1617 {
17- PythonEngine . EndAllowThreads ( Handle ) ;
18+ Handle = new PythonHandle ( ) ;
1819 }
1920 }
2021}
Original file line number Diff line number Diff line change @@ -42,11 +42,13 @@ static PythonHandle()
4242 . GetValue ( null ) ! ;
4343 }
4444
45+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4546 public PythonHandle ( )
4647 {
4748 GILState = PyGILState_Ensure ( ) ;
4849 }
4950
51+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5052 public void Dispose ( )
5153 {
5254 PyGILState_Release ( GILState ) ;
You can’t perform that action at this time.
0 commit comments