[PATCH 06/14] pytdb: Add support for tdb_transaction_start_nonblock()
Kirill Smelkov
kirr at landau.phys.spbu.ru
Sat Oct 2 07:43:45 MDT 2010
From: Kirill Smelkov <kirr at mns.spb.ru>
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 07ac524..7ed95a8 100644
--- a/lib/tdb/pytdb.c
+++ b/lib/tdb/pytdb.c
@@ -149,6 +149,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);
@@ -450,6 +456,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 3d3118b..576baca 100644
--- a/lib/tdb/python/tests/simple.py
+++ b/lib/tdb/python/tests/simple.py
@@ -161,6 +161,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_iterkeys(self):
self.tdb["bloe"] = "2"
self.tdb["bla"] = "25"
--
1.7.3.1.50.g1e633
More information about the samba-technical
mailing list