Fix a race, this also make it more efficient because we only grab lock once.
Fix a race, this also make it more efficient because we only grab lock once.

pscedu/slash2-stable,pscedu/slash2-stable,pscedu/slash2-stable,pscedu/slash2-stable,pscedu/slash2-stable,pscedu/slash2-stable,pscedu/slash2-stable