Replaced CriticalSection with cross-platform Mutex