Cavity-assisted nondestructive laser cooling of atomic qubits