Factor out WaitQueue into a separate file

This is a simple start to making the sync module less big, and more
understandable.