Description
The rwlocks are implemented following the algorithm described here: http://en.wikipedia.org/wiki/Readers-writers_problem#The_third_readers-writers_problem , which has a note:
Note that sections protected by counter_mutex could be replaced by a suitable fetch-and-add atomic instruction, saving two potential context switches in reader's code.
I should implement this, convince myself that it's right, and profile its performance against the old version.
You might argue that doing this the more clever way makes the code less maintainable, that it might accidentally have a bug that would be a lot harder to find. This is possible, although I might argue in response that the logic should never need to be changed, so if I get it right, it will be right forever. We'll have to see how much of a performance improvement it is.