You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/02/17 19:03:14 UTC

[1/2] qpid-proton git commit: PROTON-1407: pn_collector_next and pn_collector_peek are inconsistent

Repository: qpid-proton
Updated Branches:
  refs/heads/master 42d5e89ef -> 6a2316a5d


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/master
Commit: 7368c34c1d141ba7754289161453d598860ea3da
Parents: 42d5e89
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Feb 17 13:05:48 2017 -0500
Committer: Alan Conway <ac...@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


[2/2] qpid-proton git commit: PROTON-1403: Rename pn_proactor_grab -> pn_proactor_get

Posted by ac...@apache.org.
PROTON-1403: Rename pn_proactor_grab -> pn_proactor_get


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

Branch: refs/heads/master
Commit: 6a2316a5d0a4e274802de81744ceae534323ba17
Parents: 7368c34
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Feb 17 13:40:52 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Feb 17 13:40:52 2017 -0500

----------------------------------------------------------------------
 proton-c/include/proton/proactor.h | 2 +-
 proton-c/src/proactor/libuv.c      | 2 +-
 proton-c/src/tests/proactor.c      | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6a2316a5/proton-c/include/proton/proactor.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/proactor.h b/proton-c/include/proton/proactor.h
index af3acbc..94c4891 100644
--- a/proton-c/include/proton/proactor.h
+++ b/proton-c/include/proton/proactor.h
@@ -119,7 +119,7 @@ PNP_EXTERN pn_event_batch_t *pn_proactor_wait(pn_proactor_t *proactor);
  * Return a batch of events if one is available immediately, otherwise return NULL.  If it
  * does return an event batch, the rules are the same as for pn_proactor_wait()
  */
-PNP_EXTERN pn_event_batch_t *pn_proactor_grab(pn_proactor_t *proactor);
+PNP_EXTERN pn_event_batch_t *pn_proactor_get(pn_proactor_t *proactor);
 
 /**
  * Call when done handling a batch of events.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6a2316a5/proton-c/src/proactor/libuv.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/libuv.c b/proton-c/src/proactor/libuv.c
index 0e87d0a..d2badbe 100644
--- a/proton-c/src/proactor/libuv.c
+++ b/proton-c/src/proactor/libuv.c
@@ -781,7 +781,7 @@ pn_event_batch_t *pn_proactor_wait(struct pn_proactor_t* p) {
   return batch;
 }
 
-pn_event_batch_t *pn_proactor_grab(struct pn_proactor_t* p) {
+pn_event_batch_t *pn_proactor_get(struct pn_proactor_t* p) {
   uv_mutex_lock(&p->lock);
   pn_event_batch_t *batch = get_batch_lh(p);
   if (batch == NULL && !p->has_leader) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6a2316a5/proton-c/src/tests/proactor.c
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/proactor.c b/proton-c/src/tests/proactor.c
index e90c45a..9f8b1fe 100644
--- a/proton-c/src/tests/proactor.c
+++ b/proton-c/src/tests/proactor.c
@@ -90,7 +90,7 @@ static void proactor_test_init(proactor_test_t *pts, size_t n) {
 }
 
 /* Iterate over an array of proactors, draining or handling events with the non-blocking
-   pn_proactor_grab.  Continue till all handlers return H_FINISHED (and return 0) or one
+   pn_proactor_get.  Continue till all handlers return H_FINISHED (and return 0) or one
    returns H_FAILED  (and return non-0)
 */
 int proactor_test_run(proactor_test_t *pts, size_t n) {
@@ -100,7 +100,7 @@ int proactor_test_run(proactor_test_t *pts, size_t n) {
   do {
     finished = 0;
     for (proactor_test_t *pt = pts; pt < pts + n; ++pt) {
-      pn_event_batch_t *events = pn_proactor_grab(pt->proactor);
+      pn_event_batch_t *events = pn_proactor_get(pt->proactor);
       if (events) {
           pn_event_t *e;
           while ((e = pn_event_batch_next(events))) {


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