kore

a fork of the worlds most advanced web framework
Log | Files | Refs | README | LICENSE

commit fad5c6ea6f4d56cc483596a6ccdc44a3152fbaa1
parent c8795b7d7fa448d9022fb6a2cda4dda35b1cc605
Author: Joris Vink <joris@coders.se>
Date:   Mon, 22 Oct 2018 08:28:03 +0200

Give pyqueues "popnow".

Diffstat:
Minclude/kore/python_methods.h | 2++
Msrc/python.c | 18++++++++++++++++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/kore/python_methods.h b/include/kore/python_methods.h @@ -168,10 +168,12 @@ struct pyqueue { static PyObject *pyqueue_pop(struct pyqueue *, PyObject *); static PyObject *pyqueue_push(struct pyqueue *, PyObject *); +static PyObject *pyqueue_popnow(struct pyqueue *, PyObject *); static PyMethodDef pyqueue_methods[] = { METHOD("pop", pyqueue_pop, METH_NOARGS), METHOD("push", pyqueue_push, METH_VARARGS), + METHOD("popnow", pyqueue_popnow, METH_NOARGS), METHOD(NULL, NULL, -1) }; diff --git a/src/python.c b/src/python.c @@ -1447,6 +1447,24 @@ pyqueue_pop(struct pyqueue *queue, PyObject *args) } static PyObject * +pyqueue_popnow(struct pyqueue *queue, PyObject *args) +{ + PyObject *obj; + struct pyqueue_object *object; + + if ((object = TAILQ_FIRST(&queue->objects)) == NULL) { + Py_RETURN_NONE; + } + + TAILQ_REMOVE(&queue->objects, object, list); + + obj = object->obj; + kore_pool_put(&queue_object_pool, object); + + return (obj); +} + +static PyObject * pyqueue_push(struct pyqueue *queue, PyObject *args) { PyObject *obj;