replace waitlock by a RWMutex

ping @creack @crosbymichael

Fix #4677