Fix gcc compilation of mutex
Add some pre-processor gunk for thread-safety