Fixes for Max plugin compilation when not using PCH
Merge pull request #410 from zrax/pch_max_fixes

Fixes for Max plugin compilation when not using PCH
Use std::atomic_int for hsSafeRefCnt, and move it to hsRefCnt.h/cpp
Replace hsMutex with std::mutex
Replace hsSleep with std::thread::sleep_for
Use C++11 threading for hsEvent, and clean up the API a bit
Convert hsThread to a std::thread implementation
Simplify plDispatch mutexes a bit
Also replace hsCritSect (CCritSect) with std::mutex, except for one:

For reasons I  don't understand, ReadFile  behaves synchronously in the
SocketStartAsyncRead  function in  pnAceNtSocket  when a std::mutex  or
std::recursive_mutex is used instead of a CRITICAL_SECTION. If you wish
to try to  debug this, simply uncomment  the #define CRITSECT_WTF  line
at the top of hsCritSect.cpp and recompile.
Get rid of AsyncSleep
Merge pnUtRef with hsRefCnt, and remove the former
pnUtRef started at zero refs instead of one, and this is simpler
than finding and removing all the extra Ref() calls.
More std::atomic and friends
Fix the last remaining CCritSect by checking error codes before they're
overwritten by unrelated implementation-defined code.
Replace another stray CRITICAL_SECTION
Update the login dialog status message thread to std::thread
Get rid of the return value from hsThread::Run() -- it was useless anyway
Move the old IPC-based semaphore to hsGlobalSemaphore, and provide a
"normal" (inter-thread only) semaphore class.
Replace AsyncThreadCreate with hsThreads