Refactor wait timeouts.

Also, make them not write the timeout ptr if the thread stopped waiting.
Feels safer.
Update tests.