This patch simplifies the implementation and fixes#5254.
Previously, the mutex was set up as if there could be multiple writers,
and there seemed to be some confusion as to which `Writer` bits to
check, as not all were checked or set at the same time.
This could also result in the mutex being left in a non-zero state even
after unlocking all locks.
All unneeded state has been removed and extra checks have been put in
place.