Only do mutex calls when threading is enabled.

The functions for sg_lock_mutex and sg_unlock_mutex are only available
in globals.c when threading is enabled. So make sure not to call
them in other functions when threading is disabled. This clears up
some compiler warnings.
Cast pid to int to avoid compiler warning.