Received: from eggs.gnu.org ([2001:4830:134:3::10]:57543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgzos-0003Wb-43 for qemu-devel@nongnu.org; Mon, 05 Sep 2016 15:44:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgzor-0002EY-3K for qemu-devel@nongnu.org; Mon, 05 Sep 2016 15:44:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgzoq-0002EN-RK for qemu-devel@nongnu.org; Mon, 05 Sep 2016 15:44:37 -0400 From: Stefan Hajnoczi Date: Mon, 5 Sep 2016 15:42:49 -0400 Message-Id: <1473104569-6973-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1473104569-6973-1-git-send-email-stefanha@redhat.com> References: <1473104569-6973-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 3/3] trace: Avoid implicit bool->integer conversions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi From: Llu=C3=ADs Vilanova An explicit if/else is clearer than arithmetic assuming #true is 1, while the compiler should be able to generate just as optimal code. Signed-off-by: Llu=C3=ADs Vilanova Message-id: 147194273830.26836.5875729707953474838.stgit@fimbulvetr.bsc.e= s Signed-off-by: Stefan Hajnoczi --- stubs/trace-control.c | 17 +++++++++++++++-- trace/control-target.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/stubs/trace-control.c b/stubs/trace-control.c index 3740c38..2dfcd9f 100644 --- a/stubs/trace-control.c +++ b/stubs/trace-control.c @@ -19,10 +19,23 @@ void trace_event_set_state_dynamic_init(TraceEvent *e= v, bool state) void trace_event_set_state_dynamic(TraceEvent *ev, bool state) { TraceEventID id; + bool state_pre; assert(trace_event_get_state_static(ev)); id =3D trace_event_get_id(ev); - trace_events_enabled_count +=3D state - trace_events_dstate[id]; - trace_events_dstate[id] =3D state; + /* + * We ignore the "vcpu" property here, since there's no target code.= Then + * dstate can only be 1 or 0. + */ + state_pre =3D trace_events_dstate[id]; + if (state_pre !=3D state) { + if (state) { + trace_events_enabled_count++; + trace_events_dstate[id] =3D 1; + } else { + trace_events_enabled_count--; + trace_events_dstate[id] =3D 0; + } + } } =20 void trace_event_set_vcpu_state_dynamic(CPUState *vcpu, diff --git a/trace/control-target.c b/trace/control-target.c index 4ee3733..72081e2 100644 --- a/trace/control-target.c +++ b/trace/control-target.c @@ -16,10 +16,22 @@ void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state) { TraceEventID id =3D trace_event_get_id(ev); + bool state_pre; assert(trace_event_get_state_static(ev)); - /* Ignore "vcpu" property, since no vCPUs have been created yet */ - trace_events_enabled_count +=3D state - trace_events_dstate[id]; - trace_events_dstate[id] =3D state; + /* + * We ignore the "vcpu" property here, since no vCPUs have been crea= ted + * yet. Then dstate can only be 1 or 0. + */ + state_pre =3D trace_events_dstate[id]; + if (state_pre !=3D state) { + if (state) { + trace_events_enabled_count++; + trace_events_dstate[id] =3D 1; + } else { + trace_events_enabled_count--; + trace_events_dstate[id] =3D 0; + } + } } =20 void trace_event_set_state_dynamic(TraceEvent *ev, bool state) @@ -31,9 +43,18 @@ void trace_event_set_state_dynamic(TraceEvent *ev, boo= l state) trace_event_set_vcpu_state_dynamic(vcpu, ev, state); } } else { + /* Without the "vcpu" property, dstate can only be 1 or 0 */ TraceEventID id =3D trace_event_get_id(ev); - trace_events_enabled_count +=3D state - trace_events_dstate[id]; - trace_events_dstate[id] =3D state; + bool state_pre =3D trace_events_dstate[id]; + if (state_pre !=3D state) { + if (state) { + trace_events_enabled_count++; + trace_events_dstate[id] =3D 1; + } else { + trace_events_enabled_count--; + trace_events_dstate[id] =3D 0; + } + } } } =20 --=20 2.7.4