cocoa: refactor sync scheduling to a function

This extracts the scheduling logic to a single function which is nicer to keep
it consistent.

Additionally make sure we don't schedule sync operations from a sync operation
itself since that could cause deadlocks (even if it should not be happening
with the current code).