Cooling the brain and making you more attentive is the role of yawning, not increasing oxygen to the brain, according to recent research.
[P]eople do not yawn because they need oxygen, since experiments show that raising or lowering oxygen and carbon dioxide in the blood fails to produce the reaction. Rather, yawning acts as a brain-cooling mechanism. The brain burns up to a third of the calories we consume, and as a consequence generates heat.
Yawning a lot is an indication that I have a migraine on the way. I knew that frequent yawning is a symptom of migraine, but didn’t know its function. I’m not sure if the brain heats up before or during a migraine, but it certainly gets excited. Assuming the increased activity raises the brain’s temperature, yawning to cool it makes sense.