File: gil.hpp

package info (click to toggle)
yade 2025.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,308 kB
  • sloc: cpp: 93,298; python: 50,409; sh: 577; makefile: 162
file content (15 lines) | stat: -rw-r--r-- 631 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// 2009 © Václav Šmilauer <eudoxos@arcig.cz>
#pragma once
// XXX never do #include<Python.h>, see https://www.boost.org/doc/libs/1_71_0/libs/python/doc/html/building/include_issues.html
#include <boost/python/detail/wrap_python.hpp>
#include <string>
//! class (scoped lock) managing python's Global Interpreter Lock (gil)
class gilLock {
	PyGILState_STATE state;

public:
	gilLock() { state = PyGILState_Ensure(); }
	~gilLock() { PyGILState_Release(state); }
};
//! run string as python command; locks & unlocks GIL automatically
void pyRunString(const std::string& cmd, bool ignoreErrors = false, bool updateGlobals = false);