From 6a9aa2e29d67d6917983c19126a1e5e8a0e5492a Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 10 Dec 2013 16:26:42 -0500 Subject: [PATCH] context manager to lock record --- devsupApp/src/dbrec.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/devsupApp/src/dbrec.c b/devsupApp/src/dbrec.c index 9747ae7..3fa3e3e 100644 --- a/devsupApp/src/dbrec.c +++ b/devsupApp/src/dbrec.c @@ -274,6 +274,26 @@ static PyObject *pyRecord_asyncFinish(pyRecord *self, PyObject *args, PyObject * return PyLong_FromLong(ret); } +static PyObject *pyRecord_enter(pyRecord *self) +{ + dbScanLock(self->entry.precnode->precord); + + Py_RETURN_NONE; +} + +static PyObject *pyRecord_exit(pyRecord *self, PyObject *args) +{ + PyObject *t, *v, *tb; + + /* always unlock, regardless of arguments */ + dbScanUnlock(self->entry.precnode->precord); + + if(!PyArg_ParseTuple(args, "OOO", &t, &v, &tb)) + return NULL; + + Py_RETURN_FALSE; +} + static PyMethodDef pyRecord_methods[] = { {"name", (PyCFunction)pyRecord_name, METH_NOARGS, "Return record name string"}, @@ -297,6 +317,10 @@ static PyMethodDef pyRecord_methods[] = { "Begin an asynchronous action. Record must be locked!"}, {"asyncFinish", (PyCFunction)pyRecord_asyncFinish, METH_VARARGS|METH_KEYWORDS, "Complete an asynchronous action. Record must *not* be locked!"}, + {"__enter__", (PyCFunction)pyRecord_enter, METH_NOARGS, + "scan lock this record"}, + {"__exit__", (PyCFunction)pyRecord_exit, METH_VARARGS, + "scan unlock this record"}, {NULL, NULL, 0, NULL} };