diff options
author | Markus Armbruster <armbru@redhat.com> | 2013-01-25 16:43:39 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2013-02-05 21:52:55 +0100 |
commit | b6b2c9628084f1672b92393cf84039a075a95301 (patch) | |
tree | bf1f4ed008c6c5c3585a996f13d0013cf934f191 | |
parent | e722d705ae7648a6bd94848319a11eb0afd58a17 (diff) | |
download | qemu-b6b2c9628084f1672b92393cf84039a075a95301.tar.gz qemu-b6b2c9628084f1672b92393cf84039a075a95301.tar.bz2 qemu-b6b2c9628084f1672b92393cf84039a075a95301.zip |
trace: Clean up the "try to update atomic until it worked" loops
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r-- | trace/simple.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/trace/simple.c b/trace/simple.c index 592ff483cc..74701e3272 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -171,13 +171,10 @@ static gpointer writeout_thread(gpointer opaque) dropped.rec.timestamp_ns = get_clock(); dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t), dropped.rec.reserved = 0; - while (1) { + do { dropped_count = g_atomic_int_get(&dropped_events); - if (g_atomic_int_compare_and_exchange(&dropped_events, - dropped_count, 0)) { - break; - } - } + } while (!g_atomic_int_compare_and_exchange(&dropped_events, + dropped_count, 0)); dropped.rec.arguments[0] = dropped_count; unused = fwrite(&dropped.rec, dropped.rec.length, 1, trace_fp); } @@ -213,7 +210,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi uint32_t rec_len = sizeof(TraceRecord) + datasize; uint64_t timestamp_ns = get_clock(); - while (1) { + do { old_idx = g_atomic_int_get(&trace_idx); smp_rmb(); new_idx = old_idx + rec_len; @@ -223,12 +220,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi g_atomic_int_inc(&dropped_events); return -ENOSPC; } - - if (g_atomic_int_compare_and_exchange(&trace_idx, - old_idx, new_idx)) { - break; - } - } + } while (!g_atomic_int_compare_and_exchange(&trace_idx, old_idx, new_idx)); idx = old_idx % TRACE_BUF_LEN; |