-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from PDAL/gil-management
manage GIL acquisition when doing things inside of pdal::plang
- Loading branch information
Showing
9 changed files
with
108 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ | |
|
||
#include "Redirector.hpp" | ||
#include "Script.hpp" | ||
#include "gil.hpp" | ||
|
||
namespace pdal | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
pybind11/gil.h: RAII helpers for managing the GIL | ||
Copyright (c) 2016 Wenzel Jakob <[email protected]> | ||
All rights reserved. Use of this source code is governed by a | ||
BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <Python.h> | ||
|
||
|
||
namespace pdal | ||
{ | ||
namespace plang | ||
{ | ||
|
||
|
||
class gil_scoped_acquire { | ||
PyGILState_STATE state; | ||
|
||
public: | ||
gil_scoped_acquire() : state{PyGILState_Ensure()} {} | ||
gil_scoped_acquire(const gil_scoped_acquire &) = delete; | ||
gil_scoped_acquire &operator=(const gil_scoped_acquire &) = delete; | ||
~gil_scoped_acquire() { PyGILState_Release(state); } | ||
void disarm() {} | ||
}; | ||
|
||
class gil_scoped_release { | ||
PyThreadState *state; | ||
|
||
public: | ||
// PRECONDITION: The GIL must be held when this constructor is called. | ||
gil_scoped_release() { | ||
assert(PyGILState_Check()); | ||
state = PyEval_SaveThread(); | ||
} | ||
gil_scoped_release(const gil_scoped_release &) = delete; | ||
gil_scoped_release &operator=(const gil_scoped_release &) = delete; | ||
~gil_scoped_release() { PyEval_RestoreThread(state); } | ||
void disarm() {} | ||
}; | ||
|
||
|
||
|
||
|
||
} // plang | ||
|
||
} // pdal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters