replace waitlock by a RWMutex

ping @creack @crosbymichael

Fixes #4677