From commits-return-46839-archive-asf-public=cust-asf.ponee.io@qpid.apache.org Mon Sep 10 22:19:46 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id E1ABD18067E for ; Mon, 10 Sep 2018 22:19:45 +0200 (CEST) Received: (qmail 88351 invoked by uid 500); 10 Sep 2018 20:19:45 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 88324 invoked by uid 99); 10 Sep 2018 20:19:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Sep 2018 20:19:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 87136E0007; Mon, 10 Sep 2018 20:19:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aconway@apache.org To: commits@qpid.apache.org Date: Mon, 10 Sep 2018 20:19:45 -0000 Message-Id: <84cd45a1d22f419ba6e859bef9741267@git.apache.org> In-Reply-To: <70b0299a97964d9388afc58768eed8ef@git.apache.org> References: <70b0299a97964d9388afc58768eed8ef@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Tue Sep 4 19:32:59 2018 -0400 Committer: Alan Conway 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