Backport some fixes to sys_domicrosleep from vanilla.
Massaged the routine a bit to bring it more in line with what vanilla currently has, and backported some recent changes in rev. 1f383be3 and rev. ff9e52c6 from vanilla which are supposed to fix some bugs in sys_domicrosleep.