Atomic spin squeezing in an optical cavity