summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/python/uwsgi_pymodule.c69
-rw-r--r--t/sharedarea/sharedarea_incdec.ini6
-rw-r--r--t/sharedarea/sharedarea_incdec.py34
3 files changed, 109 insertions, 0 deletions
diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c
index 34f4df88..54273199 100644
--- a/plugins/python/uwsgi_pymodule.c
+++ b/plugins/python/uwsgi_pymodule.c
@@ -1449,6 +1449,72 @@ PyObject *py_uwsgi_sharedarea_inc64(PyObject * self, PyObject * args) {
}
+PyObject *py_uwsgi_sharedarea_inc32(PyObject * self, PyObject * args) {
+ int id;
+ uint64_t pos = 0;
+ int32_t value = 1;
+
+ if (!PyArg_ParseTuple(args, "iL|i:sharedarea_inc32", &id, &pos, &value)) {
+ return NULL;
+ }
+
+ UWSGI_RELEASE_GIL
+ int ret = uwsgi_sharedarea_inc32(id, pos, value);
+ UWSGI_GET_GIL
+
+ if (ret) {
+ return PyErr_Format(PyExc_ValueError, "error calling uwsgi_sharedarea_inc32()");
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+
+}
+
+PyObject *py_uwsgi_sharedarea_dec64(PyObject * self, PyObject * args) {
+ int id;
+ uint64_t pos = 0;
+ int64_t value = 1;
+
+ if (!PyArg_ParseTuple(args, "iL|l:sharedarea_dec64", &id, &pos, &value)) {
+ return NULL;
+ }
+
+ UWSGI_RELEASE_GIL
+ int ret = uwsgi_sharedarea_dec64(id, pos, value);
+ UWSGI_GET_GIL
+
+ if (ret) {
+ return PyErr_Format(PyExc_ValueError, "error calling uwsgi_sharedarea_dec64()");
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+
+}
+
+PyObject *py_uwsgi_sharedarea_dec32(PyObject * self, PyObject * args) {
+ int id;
+ uint64_t pos = 0;
+ int32_t value = 1;
+
+ if (!PyArg_ParseTuple(args, "iL|i:sharedarea_dec32", &id, &pos, &value)) {
+ return NULL;
+ }
+
+ UWSGI_RELEASE_GIL
+ int ret = uwsgi_sharedarea_dec32(id, pos, value);
+ UWSGI_GET_GIL
+
+ if (ret) {
+ return PyErr_Format(PyExc_ValueError, "error calling uwsgi_sharedarea_dec32()");
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+
+}
+
PyObject *py_uwsgi_sharedarea_write32(PyObject * self, PyObject * args) {
int id;
uint64_t pos = 0;
@@ -2569,6 +2635,9 @@ static PyMethodDef uwsgi_sa_methods[] = {
{"sharedarea_write16", py_uwsgi_sharedarea_write16, METH_VARARGS, ""},
{"sharedarea_inclong", py_uwsgi_sharedarea_inc64, METH_VARARGS, ""},
{"sharedarea_inc64", py_uwsgi_sharedarea_inc64, METH_VARARGS, ""},
+ {"sharedarea_inc32", py_uwsgi_sharedarea_inc32, METH_VARARGS, ""},
+ {"sharedarea_dec64", py_uwsgi_sharedarea_dec64, METH_VARARGS, ""},
+ {"sharedarea_dec32", py_uwsgi_sharedarea_dec32, METH_VARARGS, ""},
{"sharedarea_rlock", py_uwsgi_sharedarea_rlock, METH_VARARGS, ""},
{"sharedarea_wlock", py_uwsgi_sharedarea_wlock, METH_VARARGS, ""},
{"sharedarea_unlock", py_uwsgi_sharedarea_unlock, METH_VARARGS, ""},
diff --git a/t/sharedarea/sharedarea_incdec.ini b/t/sharedarea/sharedarea_incdec.ini
new file mode 100644
index 00000000..7d0b2a74
--- /dev/null
+++ b/t/sharedarea/sharedarea_incdec.ini
@@ -0,0 +1,6 @@
+[uwsgi]
+socket = /tmp/foo
+
+sharedarea = size=64
+
+pyrun = t/sharedarea/%n.py
diff --git a/t/sharedarea/sharedarea_incdec.py b/t/sharedarea/sharedarea_incdec.py
new file mode 100644
index 00000000..884fbfea
--- /dev/null
+++ b/t/sharedarea/sharedarea_incdec.py
@@ -0,0 +1,34 @@
+import uwsgi
+import unittest
+
+class SharedareaTest(unittest.TestCase):
+
+ def setUp(self):
+ uwsgi.sharedarea_write(0, 0, '\0' * 64)
+
+ def test_32(self):
+ uwsgi.sharedarea_write32(0, 0, 17)
+ self.assertEqual(uwsgi.sharedarea_read32(0, 0), 17)
+
+ def test_inc32(self):
+ uwsgi.sharedarea_write32(0, 4, 30)
+ uwsgi.sharedarea_inc32(0, 4, 3)
+ self.assertEqual(uwsgi.sharedarea_read32(0, 4), 33)
+
+ def test_dec32(self):
+ uwsgi.sharedarea_write32(0, 5, 30)
+ uwsgi.sharedarea_dec32(0, 5, 4)
+ self.assertEqual(uwsgi.sharedarea_read32(0, 5), 26)
+
+ def test_inc64(self):
+ uwsgi.sharedarea_write64(0, 8, 17 * (1024 ** 5))
+ uwsgi.sharedarea_inc64(0, 8, 1)
+ self.assertEqual(uwsgi.sharedarea_read64(0, 8), 17 * (1024 ** 5) + 1)
+
+ def test_dec64(self):
+ uwsgi.sharedarea_write64(0, 8, 30 * (1024 ** 5))
+ uwsgi.sharedarea_dec64(0, 8, 30 * (1024 ** 5) - 1)
+ self.assertEqual(uwsgi.sharedarea_read64(0, 8), 1)
+
+
+unittest.main()