OS X compatibility fixes

Code fixes for compatibility with OS X, see https://github.com/minetest/minetest/issues/1242. I have tested this on OS X and Linux.
OK, added a mutex for semcount increments/decrements.