Move to sync.RWMutex

This both simplifies the lock handling code and removes a data race
where w.idx could change and overwrite a very old entry that was being
fetched.