From 609b79b38868c28df86bd3ad93b00cebe43fff11 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Mon, 12 Aug 2024 15:28:49 +1000 Subject: [PATCH] Add some more threading API calls --- src/CSnakes.Runtime/CPython/GIL.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/CSnakes.Runtime/CPython/GIL.cs b/src/CSnakes.Runtime/CPython/GIL.cs index 483a5d0d..6f5a9494 100644 --- a/src/CSnakes.Runtime/CPython/GIL.cs +++ b/src/CSnakes.Runtime/CPython/GIL.cs @@ -24,4 +24,18 @@ internal unsafe partial class CPythonAPI /// 1 if held, 0 if not. [LibraryImport(PythonLibraryName)] internal static partial int PyGILState_Check(); + + internal static int GetNativeThreadId() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + return GetCurrentThreadId(); + else + return -1; + } + + [LibraryImport("kernel32.dll")] + private static partial int GetCurrentThreadId(); + + [LibraryImport(PythonLibraryName)] + internal static partial int Py_MakePendingCalls(); }