qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [25/38] qpid-proton git commit: PROTON-1407: pn_collector_next and pn_collector_peek are inconsistent
Date Thu, 23 Feb 2017 22:51:32 GMT
PROTON-1407: pn_collector_next and pn_collector_peek are inconsistent

Make the behavior consistent as follows:
- peek returns the head of the collector
- pop() and next() remove the head of the collector, pop() discards it, next() returns it
- next() keeps the returned event alive until the following call to next()

next() no longer uses the head of the collector to keep returned events alive, the
returned event is remembered via a separate pointer.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/7368c34c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/7368c34c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/7368c34c

Branch: refs/heads/go1
Commit: 7368c34c1d141ba7754289161453d598860ea3da
Parents: 42d5e89
Author: Alan Conway <aconway@redhat.com>
Authored: Fri Feb 17 13:05:48 2017 -0500
Committer: Alan Conway <aconway@redhat.com>
Committed: Fri Feb 17 13:05:48 2017 -0500

----------------------------------------------------------------------
 proton-c/include/proton/event.h       | 19 ++++-----------
 proton-c/src/core/connection_driver.c |  3 +--
 proton-c/src/core/event.c             | 38 ++++++++++++++++--------------
 proton-c/src/proactor/libuv.c         |  8 +------
 4 files changed, 27 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7368c34c/proton-c/include/proton/event.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/event.h b/proton-c/include/proton/event.h
index 3cfcc82..b4dbfeb 100644
--- a/proton-c/include/proton/event.h
+++ b/proton-c/include/proton/event.h
@@ -431,7 +431,7 @@ PN_EXTERN pn_event_t *pn_collector_put(pn_collector_t *collector,
 PN_EXTERN pn_event_t *pn_collector_peek(pn_collector_t *collector);
 
 /**
- * Clear the head event on a collector.
+ * Remove the head event on a collector.
  *
  * @param[in] collector a collector object
  * @return true if the event was popped, false if the collector is empty
@@ -439,14 +439,8 @@ PN_EXTERN pn_event_t *pn_collector_peek(pn_collector_t *collector);
 PN_EXTERN bool pn_collector_pop(pn_collector_t *collector);
 
 /**
- * Return the next event to be handled.
- *
- * Returns the head event if it has not previously been returned by
- * pn_collector_next(), otherwise does pn_collector_pop() and returns
- * the new head event.
- *
- * The returned pointer is valid till the next call of pn_collector_pop(),
- * pn_collector_next(), pn_collector_release() or pn_collector_free()
+ * Pop and return the head event, returns NULL if the collector is empty.
+ * The returned pointer is valid till the next call of pn_collector_next().
  *
  * @param[in] collector a collector object
  * @return the next event.
@@ -454,10 +448,7 @@ PN_EXTERN bool pn_collector_pop(pn_collector_t *collector);
 PN_EXTERN pn_event_t *pn_collector_next(pn_collector_t *collector);
 
 /**
- * Return the same event as the previous call to pn_collector_next()
- *
- * The returned pointer is valid till the next call of pn_collector_pop(),
- * pn_collector_next(), pn_collector_release() or pn_collector_free()
+ * Return the same pointer as the most recent call to pn_collector_next().
  *
  * @param[in] collector a collector object
  * @return a pointer to the event returned by previous call to pn_collector_next()
@@ -465,7 +456,7 @@ PN_EXTERN pn_event_t *pn_collector_next(pn_collector_t *collector);
 PN_EXTERN pn_event_t *pn_collector_prev(pn_collector_t *collector);
 
 /**
- * Check if there are more events after the current event. If this
+ * Check if there are more events after the current head event. If this
  * returns true, then pn_collector_peek() will return an event even
  * after pn_collector_pop() is called.
  *

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7368c34c/proton-c/src/core/connection_driver.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/connection_driver.c b/proton-c/src/core/connection_driver.c
index 63eed09..3393e64 100644
--- a/proton-c/src/core/connection_driver.c
+++ b/proton-c/src/core/connection_driver.c
@@ -127,8 +127,7 @@ pn_event_t* pn_connection_driver_next_event(pn_connection_driver_t *d)
{
 }
 
 bool pn_connection_driver_has_event(pn_connection_driver_t *d) {
-  pn_collector_t *c = pn_connection_collector(d->connection);
-  return pn_collector_more(c) || (pn_collector_peek(c) && pn_collector_peek(c) !=
pn_collector_prev(c));
+  return pn_collector_peek(pn_connection_collector(d->connection));
 }
 
 bool pn_connection_driver_finished(pn_connection_driver_t *d) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7368c34c/proton-c/src/core/event.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/event.c b/proton-c/src/core/event.c
index e213c8f..7a80a72 100644
--- a/proton-c/src/core/event.c
+++ b/proton-c/src/core/event.c
@@ -28,8 +28,8 @@ struct pn_collector_t {
   pn_list_t *pool;
   pn_event_t *head;
   pn_event_t *tail;
+  pn_event_t *prev;         /* event returned by previous call to pn_collector_next() */
   bool freed;
-  bool head_returned;         /* Head has been returned by pn_collector_next() */
 };
 
 struct pn_event_t {
@@ -46,6 +46,7 @@ static void pn_collector_initialize(pn_collector_t *collector)
   collector->pool = pn_list(PN_OBJECT, 0);
   collector->head = NULL;
   collector->tail = NULL;
+  collector->prev = NULL;
   collector->freed = false;
 }
 
@@ -171,35 +172,36 @@ pn_event_t *pn_collector_peek(pn_collector_t *collector)
   return collector->head;
 }
 
-bool pn_collector_pop(pn_collector_t *collector)
-{
-  collector->head_returned = false;
+// Advance head pointer for pop or next, return the old head.
+static pn_event_t *pop_internal(pn_collector_t *collector) {
   pn_event_t *event = collector->head;
   if (event) {
     collector->head = event->next;
-  } else {
-    return false;
+    if (!collector->head) {
+      collector->tail = NULL;
+    }
   }
+  return event;
+}
 
-  if (!collector->head) {
-    collector->tail = NULL;
+bool pn_collector_pop(pn_collector_t *collector) {
+  pn_event_t *event = pop_internal(collector);
+  if (event) {
+    pn_decref(event);
   }
-
-  pn_decref(event);
-  return true;
+  return event;
 }
 
-pn_event_t *pn_collector_next(pn_collector_t *collector)
-{
-  if (collector->head_returned) {
-    pn_collector_pop(collector);
+pn_event_t *pn_collector_next(pn_collector_t *collector) {
+  if (collector->prev) {
+    pn_decref(collector->prev);
   }
-  collector->head_returned = collector->head;
-  return collector->head;
+  collector->prev = pop_internal(collector);
+  return collector->prev;
 }
 
 pn_event_t *pn_collector_prev(pn_collector_t *collector) {
-  return collector->head_returned ? collector->head : NULL;
+  return collector->prev;
 }
 
 bool pn_collector_more(pn_collector_t *collector)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7368c34c/proton-c/src/proactor/libuv.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/libuv.c b/proton-c/src/proactor/libuv.c
index 0a10ac9..0e87d0a 100644
--- a/proton-c/src/proactor/libuv.c
+++ b/proton-c/src/proactor/libuv.c
@@ -621,17 +621,11 @@ static void pconnection_to_worker(pconnection_t *pc) {
   to_worker(&pc->psocket);
 }
 
-/* TODO aconway 2017-02-16: simplify collector API*/
-static bool collector_has_next(pn_collector_t *c) {
-  return pn_collector_more(c) ||
-    (pn_collector_peek(c) && pn_collector_peek(c) != pn_collector_prev(c));
-}
-
 /* Can't really detach a listener, as on_connection can always be called.
    Generate events here safely.
 */
 static void listener_to_worker(pn_listener_t *l) {
-  if (collector_has_next(l->collector)) { /* Already have events */
+  if (pn_collector_peek(l->collector)) { /* Already have events */
     to_worker(&l->psocket);
   } else if (l->err) {
     if (l->err != UV_EOF) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message