As a lot of other people mentioned here, it's probably have nothing to do with your cognitive abilities, but rather with your emotional state.
Recently, I found out that stressing my body can "reset" my mental and emotional state when I'm in a bad spot (similar to what you described).
I stress my body by doing a physical activity (like running or cycling) or going on a diet (skipping 1 or more lunch). I'm trying to do the opposite of what I feel I want to do (eating more sugar-stuff and doing nothing).