Optimize locking in atomic