I wonder whether do we need _mark variants, and also why in pytdb there is a name mismatch with C tdb? e.g.
tdb_lockall_read() is called tdb.read_lock_all() in Python. I've sticked to this rule, but it looks confusing to me... Cc: [email protected] Signed-off-by: Kirill Smelkov <[email protected]> --- lib/tdb/pytdb.c | 77 ++++++++++++++++++++++++++++++++++++++++ lib/tdb/python/tests/simple.py | 20 ++++++++++ 2 files changed, 97 insertions(+), 0 deletions(-) diff --git a/lib/tdb/pytdb.c b/lib/tdb/pytdb.c index 42df639..07ac524 100644 --- a/lib/tdb/pytdb.c +++ b/lib/tdb/pytdb.c @@ -196,6 +196,71 @@ static PyObject *obj_lockall_read_nonblock(PyTdbObject *self) PyTdb_LOCK_NONBLOCK_RET_OR_RAISE(ret, self->ctx); } + +static PyObject *obj_chainlock(PyTdbObject *self, PyObject *args) +{ + int ret; + TDB_DATA key; + PyTdb_ARGS_AS_TDBDATA(args, &key); + + ret = tdb_chainlock(self->ctx, key); + PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); + Py_RETURN_NONE; +} + +static PyObject *obj_chainunlock(PyTdbObject *self, PyObject *args) +{ + int ret; + TDB_DATA key; + PyTdb_ARGS_AS_TDBDATA(args, &key); + + ret = tdb_chainunlock(self->ctx, key); + PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); + Py_RETURN_NONE; +} + +static PyObject *obj_chainlock_read(PyTdbObject *self, PyObject *args) +{ + int ret; + TDB_DATA key; + PyTdb_ARGS_AS_TDBDATA(args, &key); + + ret = tdb_chainlock_read(self->ctx, key); + PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); + Py_RETURN_NONE; +} + +static PyObject *obj_chainunlock_read(PyTdbObject *self, PyObject *args) +{ + int ret; + TDB_DATA key; + PyTdb_ARGS_AS_TDBDATA(args, &key); + + ret = tdb_chainunlock_read(self->ctx, key); + PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); + Py_RETURN_NONE; +} + +static PyObject *obj_chainlock_nonblock(PyTdbObject *self, PyObject *args) +{ + int ret; + TDB_DATA key; + PyTdb_ARGS_AS_TDBDATA(args, &key); + + ret = tdb_chainlock_nonblock(self->ctx, key); + PyTdb_LOCK_NONBLOCK_RET_OR_RAISE(ret, self->ctx); +} + +static PyObject *obj_chainlock_read_nonblock(PyTdbObject *self, PyObject *args) +{ + int ret; + TDB_DATA key; + PyTdb_ARGS_AS_TDBDATA(args, &key); + + ret = tdb_chainlock_read_nonblock(self->ctx, key); + PyTdb_LOCK_NONBLOCK_RET_OR_RAISE(ret, self->ctx); +} + static PyObject *obj_close(PyTdbObject *self) { int ret; @@ -394,6 +459,18 @@ static PyMethodDef tdb_object_methods[] = { "S.lock_all_nonblock() -> True|False" }, { "read_lock_all_nonblock", (PyCFunction)obj_lockall_read_nonblock, METH_NOARGS, "S.read_lock_all_nonblock() -> True|False" }, + { "chainlock", (PyCFunction)obj_chainlock, METH_VARARGS, + "S.chainlock(key) -> None" }, + { "chainunlock", (PyCFunction)obj_chainunlock, METH_VARARGS, + "S.chainunlock() -> None" }, + { "read_chainlock", (PyCFunction)obj_chainlock_read, METH_VARARGS, + "S.read_chainlock(key) -> None" }, + { "read_chainunlock", (PyCFunction)obj_chainunlock_read, METH_VARARGS, + "S.read_chainunlock() -> None" }, + { "chainlock_nonblock", (PyCFunction)obj_chainlock_nonblock, METH_VARARGS, + "S.chainlock_nonblock(key) -> True|False" }, + { "read_chainlock_nonblock", (PyCFunction)obj_chainlock_read_nonblock, METH_VARARGS, + "S.chainlock_read_nonblock(key) -> True|False" }, { "close", (PyCFunction)obj_close, METH_NOARGS, NULL }, { "get", (PyCFunction)obj_get, METH_VARARGS, "S.get(key) -> value\n" "Fetch a value." }, diff --git a/lib/tdb/python/tests/simple.py b/lib/tdb/python/tests/simple.py index eb7fd17..3d3118b 100644 --- a/lib/tdb/python/tests/simple.py +++ b/lib/tdb/python/tests/simple.py @@ -78,6 +78,26 @@ class SimpleTdbTests(TestCase): locked = self.tdb.read_lock_all_nonblock() self.tdb.read_unlock_all() + def test_chainlock(self): + self.tdb.chainlock("foo") + self.tdb.chainunlock("foo") + + def test_chainlock_read(self): + self.tdb.read_chainlock("foo") + self.tdb.read_chainunlock("foo") + + def test_chainlock_nonblock(self): + locked = False + while not locked: + locked = self.tdb.chainlock_nonblock("foo") + self.tdb.chainunlock("foo") + + def test_chainlock_read_nonblock(self): + locked = False + while not locked: + locked = self.tdb.read_chainlock_nonblock("foo") + self.tdb.read_chainunlock("foo") + def test_reopen(self): self.tdb.reopen() -- 1.7.3.1.50.g1e633 -- To UNSUBSCRIBE, email to [email protected] with a subject of "unsubscribe". Trouble? Contact [email protected]

