mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 21:51:30 +00:00
fixed #914
This commit is contained in:
@@ -1448,6 +1448,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, ""},
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
[uwsgi]
|
||||
socket = /tmp/foo
|
||||
|
||||
sharedarea = size=64
|
||||
|
||||
pyrun = t/sharedarea/%n.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()
|
||||
Reference in New Issue
Block a user