cpy3/thread.go

79 lines
2.5 KiB
Go
Raw Permalink Normal View History

2018-12-13 22:09:42 +00:00
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the MIT License.
2018-12-13 22:09:42 +00:00
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
2018-12-06 17:23:54 +00:00
package python3
/*
#include "Python.h"
*/
import "C"
2023-05-24 08:30:48 +00:00
// PyThreadState : https://docs.python.org/3/c-api/init.html#c.PyThreadState
2018-12-06 17:23:54 +00:00
type PyThreadState C.PyThreadState
2023-05-24 08:30:48 +00:00
// PyGILState is an opaque “handle” to the thread state when PyGILState_Ensure() was called, and must be passed to PyGILState_Release() to ensure Python is left in the same state
2018-12-06 17:23:54 +00:00
type PyGILState C.PyGILState_STATE
//PyEval_InitThreads : https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads
2023-05-24 08:30:48 +00:00
/*
2018-12-06 17:23:54 +00:00
func PyEval_InitThreads() {
C.PyEval_InitThreads()
}
2023-05-24 08:30:48 +00:00
*/
2018-12-06 17:23:54 +00:00
2023-05-24 08:30:48 +00:00
// PyEval_ThreadsInitialized : https://docs.python.org/3/c-api/init.html#c.PyEval_ThreadsInitialized
2018-12-06 17:23:54 +00:00
func PyEval_ThreadsInitialized() bool {
return C.PyEval_ThreadsInitialized() != 0
}
2023-05-24 08:30:48 +00:00
// PyEval_SaveThread : https://docs.python.org/3/c-api/init.html#c.PyEval_SaveThread
2018-12-06 17:23:54 +00:00
func PyEval_SaveThread() *PyThreadState {
return (*PyThreadState)(C.PyEval_SaveThread())
}
2023-05-24 08:30:48 +00:00
// PyEval_RestoreThread : https://docs.python.org/3/c-api/init.html#c.PyEval_RestoreThread
2018-12-06 17:23:54 +00:00
func PyEval_RestoreThread(tstate *PyThreadState) {
C.PyEval_RestoreThread((*C.PyThreadState)(tstate))
}
2023-05-24 08:30:48 +00:00
// PyThreadState_Get : https://docs.python.org/3/c-api/init.html#c.PyThreadState_Get
2018-12-06 17:23:54 +00:00
func PyThreadState_Get() *PyThreadState {
return (*PyThreadState)(C.PyThreadState_Get())
}
2023-05-24 08:30:48 +00:00
// PyThreadState_Swap : https://docs.python.org/3/c-api/init.html#c.PyThreadState_Swap
2018-12-06 17:23:54 +00:00
func PyThreadState_Swap(tstate *PyThreadState) *PyThreadState {
return (*PyThreadState)(C.PyThreadState_Swap((*C.PyThreadState)(tstate)))
}
2023-05-24 08:30:48 +00:00
// PyEval_ReInitThreads : https://docs.python.org/3/c-api/init.html#c.PyEval_ReInitThreads
/*
2018-12-06 17:23:54 +00:00
func PyEval_ReInitThreads() {
C.PyEval_ReInitThreads()
}
2023-05-24 08:30:48 +00:00
*/
2018-12-06 17:23:54 +00:00
2023-05-24 08:30:48 +00:00
// PyGILState_Ensure : https://docs.python.org/3/c-api/init.html#c.PyGILState_Ensure
2018-12-06 17:23:54 +00:00
func PyGILState_Ensure() PyGILState {
return PyGILState(C.PyGILState_Ensure())
}
2023-05-24 08:30:48 +00:00
// PyGILState_Release : https://docs.python.org/3/c-api/init.html#c.PyGILState_Release
2018-12-06 17:23:54 +00:00
func PyGILState_Release(state PyGILState) {
C.PyGILState_Release(C.PyGILState_STATE(state))
}
2023-05-24 08:30:48 +00:00
// PyGILState_GetThisThreadState : https://docs.python.org/3/c-api/init.html#c.PyGILState_GetThisThreadState
2018-12-06 17:23:54 +00:00
func PyGILState_GetThisThreadState() *PyThreadState {
return (*PyThreadState)(C.PyGILState_GetThisThreadState())
}
2023-05-24 08:30:48 +00:00
// PyGILState_Check : https://docs.python.org/3/c-api/init.html#c.PyGILState_Check
2018-12-06 17:23:54 +00:00
func PyGILState_Check() bool {
return C.PyGILState_Check() == 1
}