run_locked(): generic func to lock/unlock and run a callback while locked