Move to sync.RWMutex

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