Update sync.c

This file had fallen far behind other popular kernels. This is a squashed cherry-pick of Erik Gilling on this file.  There were occasional contributions from others but this was mostly all of his work.