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 2018/09/10 20:19:45 UTC

[2/6] qpid-proton git commit: PROTON-1798: [c] Fix benign race in broker.c example found by tsan

PROTON-1798: [c] Fix benign race in broker.c example found by tsan


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

Branch: refs/heads/master
Commit: c6db635838f0abb67eb37bf565d4072870e1fe9d
Parents: 407711a
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Sep 4 19:32:59 2018 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Sep 7 11:26:25 2018 -0400

----------------------------------------------------------------------
 c/examples/broker.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c6db6358/c/examples/broker.c
----------------------------------------------------------------------
diff --git a/c/examples/broker.c b/c/examples/broker.c
index 69dc536..6ffe8ed 100644
--- a/c/examples/broker.c
+++ b/c/examples/broker.c
@@ -216,7 +216,6 @@ typedef struct broker_t {
   size_t threads;
   const char *container_id;     /* AMQP container-id */
   queues_t queues;
-  bool finished;
   pn_ssl_domain_t *ssl_domain;
 } broker_t;
 
@@ -276,14 +275,14 @@ static void session_unsub(broker_t *b, pn_session_t *ssn) {
 
 static void check_condition(pn_event_t *e, pn_condition_t *cond) {
   if (pn_condition_is_set(cond)) {
-    fprintf(stderr, "%s: %s: %s\n", pn_event_type_name(pn_event_type(e)),
-            pn_condition_get_name(cond), pn_condition_get_description(cond));
+    printf("%s: %s: %s\n", pn_event_type_name(pn_event_type(e)),
+           pn_condition_get_name(cond), pn_condition_get_description(cond));
   }
 }
 
 const int WINDOW=5; /* Very small incoming credit window, to show flow control in action */
 
-static void handle(broker_t* b, pn_event_t* e) {
+static bool handle(broker_t* b, pn_event_t* e) {
   pn_connection_t *c = pn_event_connection(e);
 
   switch (pn_event_type(e)) {
@@ -418,25 +417,26 @@ static void handle(broker_t* b, pn_event_t* e) {
     break;
 
    case PN_PROACTOR_INTERRUPT:
-    b->finished = true;
     pn_proactor_interrupt(b->proactor); /* Pass along the interrupt to the other threads */
-    break;
+    return false;
 
    default:
     break;
   }
+  return true;
 }
 
 static void* broker_thread(void *void_broker) {
   broker_t *b = (broker_t*)void_broker;
+  bool finished = false;
   do {
     pn_event_batch_t *events = pn_proactor_wait(b->proactor);
     pn_event_t *e;
     while ((e = pn_event_batch_next(events))) {
-      handle(b, e);
+        if (!handle(b, e)) finished = true;
     }
     pn_proactor_done(b->proactor, events);
-  } while(!b->finished);
+  } while(!finished);
   return NULL;
 }
 


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