From f47c07c8b94103af3d36f211beae127b423124f3 Mon Sep 17 00:00:00 2001 From: Tim Head Date: Wed, 1 Feb 2017 16:21:23 +0100 Subject: [PATCH] Add a comment explaining the compare-and-swap loop --- lib/storage.hh | 7 +++++++ tests/test_countgraph.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/storage.hh b/lib/storage.hh index 6171563bb6..6a67f96a38 100644 --- a/lib/storage.hh +++ b/lib/storage.hh @@ -327,6 +327,13 @@ public: } // increase count, no checking for overflow + // current_tbl and new_tbl are the current and new bit packed values + // for the idx'th byte of the table. + // compare_exchange_weak will update the value of table[idx] if + // current_tbl is the current value (hasn't been changed by a + // different thread) if they differ the value actually stored + // in table[idx] is written to current_tbl so this is a + // compare-and-swap loop uint8_t new_count = (current_count + 1) << shift; uint8_t new_tbl = (current_tbl & ~mask) | (new_count & mask); diff --git a/tests/test_countgraph.py b/tests/test_countgraph.py index 9349ec834f..a73f306b04 100644 --- a/tests/test_countgraph.py +++ b/tests/test_countgraph.py @@ -209,8 +209,8 @@ def test_get_raw_tables(): def test_get_raw_tables_smallcountgraph(): - # smallcountgraphs store individual counts packed into a byte, the raw tables - # probably do not give users what they expect (something that can be + # smallcountgraphs store individual counts packed into a byte, the raw + # tables probably do not give users what they expect (something that can be # given to numpy.frombuffer) ht = khmer.SmallCountgraph(20, 1e5, 4) assert not hasattr(ht, 'get_raw_tables')