# include <intrin.h> // __readgsqword()
#endif
+#if defined(Py_GIL_DISABLED) && defined(__MINGW32__)
+# include <intrin.h> // __readgsqword()
+#endif
+
// Include Python header files
#include "pyport.h"
#include "pymacro.h"
tid = __readfsdword(24);
#elif defined(_MSC_VER) && defined(_M_ARM64)
tid = __getReg(18);
+#elif defined(__MINGW32__) && defined(_M_X64)
+ tid = __readgsqword(48);
+#elif defined(__MINGW32__) && defined(_M_IX86)
+ tid = __readfsdword(24);
+#elif defined(__MINGW32__) && defined(_M_ARM64)
+ tid = __getReg(18);
#elif defined(__i386__)
__asm__("movl %%gs:0, %0" : "=r" (tid)); // 32-bit always uses GS
#elif defined(__MACH__) && defined(__x86_64__)