Skip to content

Commit cd21493

Browse files
committed
Add GIL lock
1 parent 49196fc commit cd21493

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/module.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,22 @@ namespace py3lm {
17481748
}
17491749
}
17501750

1751+
struct GILLock {
1752+
GILLock() {
1753+
_state = PyGILState_Ensure();
1754+
}
1755+
1756+
~GILLock() {
1757+
PyGILState_Release(_state);
1758+
}
1759+
1760+
private:
1761+
PyGILState_STATE _state;
1762+
};
1763+
17511764
void InternalCall(MethodRef method, MemAddr data, const JitCallback::Parameters* params, const size_t, const JitCallback::Return* ret) {
1765+
GILLock lock{};
1766+
17521767
PyObject* const func = data.RCast<PyObject*>();
17531768

17541769
enum class ParamProcess {
@@ -3499,6 +3514,8 @@ namespace py3lm {
34993514

35003515
_provider->Log(std::format(LOG_PREFIX "Load plugin module '{}'", moduleName), Severity::Verbose);
35013516

3517+
GILLock lock{};
3518+
35023519
for (const auto& requiredModule : ExtractRequiredModules(filePath.string())) {
35033520
ResolveRequiredModule(requiredModule);
35043521
}
@@ -4195,6 +4212,8 @@ namespace py3lm {
41954212
return;
41964213
}
41974214

4215+
GILLock lock{};
4216+
41984217
PyObject* const nameString = PyUnicode_DecodeFSDefault(name.data());
41994218
if (!nameString) {
42004219
LogError();

0 commit comments

Comments
 (0)