summaryrefslogtreecommitdiffstats
path: root/libvir.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2006-10-24 20:28:16 +0000
committerDaniel P. Berrange <berrange@redhat.com>2006-10-24 20:28:16 +0000
commit54db0825da704d121264647798fdd829a3ade6e2 (patch)
tree6b8a35f79a855041cdf8c3b57156a566516d149d /libvir.c
parent6606a75667802eaf7d956fb6a61ffaeaece9385d (diff)
downloadlibvirt-python-v6-54db0825da704d121264647798fdd829a3ade6e2.tar.gz
libvirt-python-v6-54db0825da704d121264647798fdd829a3ade6e2.tar.xz
libvirt-python-v6-54db0825da704d121264647798fdd829a3ade6e2.zip
Make python bindings threaded, by dropping/acquiring Python GIL where needed
Diffstat (limited to 'libvir.c')
-rw-r--r--libvir.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/libvir.c b/libvir.c
index 907383b..3d580e5 100644
--- a/libvir.c
+++ b/libvir.c
@@ -18,6 +18,8 @@
void initlibvirmod(void);
PyObject *libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args);
+
+
/************************************************************************
* *
* Global error handler at the Python level *
@@ -40,6 +42,8 @@ libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, virErrorPtr err)
if ((err == NULL) || (err->code == VIR_ERR_OK))
return;
+ LIBVIRT_ENSURE_THREAD_STATE;
+
if ((libvirt_virPythonErrorFuncHandler == NULL) ||
(libvirt_virPythonErrorFuncHandler == Py_None)) {
virDefaultErrorFunc(err);
@@ -63,6 +67,8 @@ libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, virErrorPtr err)
Py_XDECREF(list);
Py_XDECREF(result);
}
+
+ LIBVIRT_RELEASE_THREAD_STATE;
}
static PyObject *
@@ -124,7 +130,9 @@ libvirt_virDomainFree(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(NULL);
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+ LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virDomainFree(domain);
+ LIBVIRT_END_ALLOW_THREADS;
py_retval = libvirt_intWrap((int) c_retval);
return(py_retval);
}
@@ -140,7 +148,9 @@ libvirt_virConnectClose(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(NULL);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+ LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virConnectClose(conn);
+ LIBVIRT_END_ALLOW_THREADS;
py_retval = libvirt_intWrap((int) c_retval);
return(py_retval);
}
@@ -158,7 +168,9 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
return(NULL);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+ LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virConnectListDomains(conn, &ids[0], 500);
+ LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0) {
Py_INCREF(Py_None);
return(Py_None);
@@ -182,7 +194,9 @@ libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(NULL);
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+ LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virDomainGetInfo(domain, &info);
+ LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0) {
Py_INCREF(Py_None);
return(Py_None);
@@ -209,7 +223,9 @@ libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(NULL);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+ LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virNodeGetInfo(conn, &info);
+ LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0) {
Py_INCREF(Py_None);
return(Py_None);
@@ -232,6 +248,7 @@ libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
unsigned char uuid[16];
virDomainPtr domain;
PyObject *pyobj_domain;
+ int c_retval;
if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUID", &pyobj_domain))
return(NULL);
@@ -241,7 +258,11 @@ libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
Py_INCREF(Py_None);
return(Py_None);
}
- if (virDomainGetUUID(domain, &uuid[0]) < 0) {
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virDomainGetUUID(domain, &uuid[0]);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (c_retval < 0) {
Py_INCREF(Py_None);
return(Py_None);
}
@@ -268,7 +289,9 @@ libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(Py_None);
}
+ LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virDomainLookupByUUID(conn, uuid);
+ LIBVIRT_END_ALLOW_THREADS;
py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval);
return(py_retval);
}