Split msgpipe handling logic from wait/resched.

This way I can reuse it for the callback stuff.
Reorganize msgpipes code a bit to prep. for cbs.

No real changes.
Adjust some helpers for msgpipes.
Refactor and add a way to remove msgpipe waits.
Add callback handlers for msgpipes.
Merge pull request #3696 from unknownbrackets/msgpipes

Add callback handlers to msgpipes as well