gil_releaser.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, RWTH Aachen University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of RWTH Aachen University nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Bjarne von Horn */
36 
37 #pragma once
38 
39 #include <utility>
40 #include <Python.h>
41 
42 namespace moveit
43 {
44 namespace py_bindings_tools
45 {
54 class GILReleaser
55 {
56  PyThreadState* m_thread_state;
57 
58 public:
60  GILReleaser() noexcept
61  {
62  m_thread_state = PyEval_SaveThread();
63  }
65  ~GILReleaser() noexcept
66  {
67  if (m_thread_state)
68  {
69  PyEval_RestoreThread(m_thread_state);
70  m_thread_state = nullptr;
71  }
72  }
73 
74  GILReleaser(const GILReleaser&) = delete;
75  GILReleaser(GILReleaser&& other) noexcept
76  {
77  m_thread_state = other.m_thread_state;
78  other.m_thread_state = nullptr;
79  }
80 
81  GILReleaser& operator=(const GILReleaser&) = delete;
82  GILReleaser& operator=(GILReleaser&& other) noexcept
83  {
84  GILReleaser copy(std::move(other));
85  this->swap(copy);
86  return *this;
87  }
88 
89  void swap(GILReleaser& other) noexcept
90  {
91  std::swap(other.m_thread_state, m_thread_state);
92  }
93 };
94 
95 } // namespace py_bindings_tools
96 } // namespace moveit
moveit::py_bindings_tools::GILReleaser::m_thread_state
PyThreadState * m_thread_state
Definition: gil_releaser.h:152
moveit::py_bindings_tools::GILReleaser::GILReleaser
GILReleaser() noexcept
Release the GIL on construction
Definition: gil_releaser.h:156
copy
ReturnMatrix copy(const Eigen::MatrixBase< Matrix > &mat)
moveit::py_bindings_tools::GILReleaser::~GILReleaser
~GILReleaser() noexcept
Reacquire the GIL on destruction
Definition: gil_releaser.h:161
moveit::py_bindings_tools::GILReleaser::operator=
GILReleaser & operator=(const GILReleaser &)=delete
moveit
moveit::py_bindings_tools::GILReleaser::swap
void swap(GILReleaser &other) noexcept
Definition: gil_releaser.h:185


planning_interface
Author(s): Ioan Sucan
autogenerated on Sat Apr 27 2024 02:27:01