Adds locks in setstats.