mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-05 14:11:43 +00:00
feat: scoped_critical_section (#5684)
* feat: scoped_critical_section Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * refactor: pull out to file Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * style: pre-commit fixes * fix: GIL code in some compilers Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * fix: move to correct spot Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <pybind11/critical_section.h>
|
||||
#include <pybind11/embed.h>
|
||||
|
||||
// Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to
|
||||
@@ -365,15 +366,11 @@ TEST_CASE("Threads") {
|
||||
#ifdef Py_GIL_DISABLED
|
||||
# if PY_VERSION_HEX < 0x030E0000
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
locals["count"] = locals["count"].cast<int>() + 1;
|
||||
# else
|
||||
Py_BEGIN_CRITICAL_SECTION(locals.ptr());
|
||||
locals["count"] = locals["count"].cast<int>() + 1;
|
||||
Py_END_CRITICAL_SECTION();
|
||||
py::scoped_critical_section lock(locals);
|
||||
# endif
|
||||
#else
|
||||
locals["count"] = locals["count"].cast<int>() + 1;
|
||||
#endif
|
||||
locals["count"] = locals["count"].cast<int>() + 1;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user