Skip to content

Commit

Permalink
Add a comment explaining the compare-and-swap loop
Browse files Browse the repository at this point in the history
  • Loading branch information
betatim committed Feb 14, 2017
1 parent 75c2820 commit f47c07c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/storage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/test_countgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit f47c07c

Please sign in to comment.