Put HasData() back inside mutex lock.

This is necessary to ensure there's not a race between when there's no data and
when we block waiting for the conditional variable to tell us there is data. I
accidentally pulled this out during the last bugfix.