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 1, 2017
1 parent 641436f commit 988cf32
Showing 1 changed file with 7 additions and 0 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

0 comments on commit 988cf32

Please sign in to comment.