[PATCH 13/14] pytdb: Add support for tdb_transaction_start_nonblock()
Kirill Smelkov
kirr at landau.phys.spbu.ru
Sun Sep 19 03:53:31 MDT 2010
Signed-off-by: Kirill Smelkov <kirr at landau.phys.spbu.ru>
---
lib/tdb/pytdb.c | 9 +++++++++
lib/tdb/python/tests/simple.py | 9 +++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/lib/tdb/pytdb.c b/lib/tdb/pytdb.c
index 98a7b2b..4fddb79 100644
--- a/lib/tdb/pytdb.c
+++ b/lib/tdb/pytdb.c
@@ -138,6 +138,12 @@ static PyObject *obj_transaction_start(PyTdbObject *self)
Py_RETURN_NONE;
}
+static PyObject *obj_transaction_start_nonblock(PyTdbObject *self)
+{
+ int ret = tdb_transaction_start_nonblock(self->ctx);
+ PyTdb_LOCK_NONBLOCK_RET_OR_RAISE(ret, self->ctx);
+}
+
static PyObject *obj_reopen(PyTdbObject *self)
{
int ret = tdb_reopen(self->ctx);
@@ -455,6 +461,9 @@ static PyMethodDef tdb_object_methods[] = {
{ "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS,
"S.transaction_start() -> None\n"
"Start a new transaction." },
+ { "transaction_start_nonblock", (PyCFunction)obj_transaction_start_nonblock, METH_NOARGS,
+ "S.transaction_start_nonblock() -> True|False\n"
+ "Try to start new transaction without blocking" },
{ "reopen", (PyCFunction)obj_reopen, METH_NOARGS, "Reopen this file." },
{ "lock_all", (PyCFunction)obj_lockall, METH_NOARGS, NULL },
{ "unlock_all", (PyCFunction)obj_unlockall, METH_NOARGS, NULL },
diff --git a/lib/tdb/python/tests/simple.py b/lib/tdb/python/tests/simple.py
index eeefd66..9bd63ff 100644
--- a/lib/tdb/python/tests/simple.py
+++ b/lib/tdb/python/tests/simple.py
@@ -147,6 +147,15 @@ class SimpleTdbTests(TestCase):
self.tdb.transaction_commit()
self.assertEquals("1", self.tdb["bloe"])
+ def test_transaction_start_nonblock(self):
+ self.tdb["bloe"] = "2"
+ in_txn = False
+ while not in_txn:
+ in_txn = self.tdb.transaction_start_nonblock()
+ self.tdb["bloe"] = "1"
+ self.tdb.transaction_commit()
+ self.assertEquals("1", self.tdb["bloe"])
+
def test_iterator(self):
self.tdb["bloe"] = "2"
self.tdb["bla"] = "hoi"
--
1.7.3.rc2
More information about the samba-technical
mailing list