TOE LOCKING TENDON
Birds don't have to stay awake thinking about staying on their perches while they sleep. Why don't they, including parrots, fall off of their perches or tree branches while they are resting or sleeping? The reason is that they have a tendon that comes down from from their lower leg bone, goes through the ankle and then automatically locks their toes around the perch.
If they have to move fast or wake up straightening their legs will unlock the tendon.