Mode stability of lasers and periodic optical systems