Implement atomicReadMVar, fixing #4001.

We add the invariant to the MVar blocked threads queue that
threads blocked on an atomic read are always at the front of
the queue.  This invariant is easy to maintain, since takers
are only ever added to the end of the queue.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
Add LOCK_CLOSURE macro for use in C--, which inlines the capability check.

This patch also tweaks lockClosure to be INLINE_HEADER, so C-- clients
don't accidentally use them and updates some other code which locks closures
to do the capability check.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
Don't call dirty_MVAR on atomicReadMVar unless we change the MVar.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
Implement tryAtomicReadMVar#.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
Release note for atomicReadMVar and friends.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
Fix typo in description
Binary: Make lazyGet more thread-safe

All values read lazily from the same BinHandle share the same mutable
offset variable (_off_r). If two such lazy values are simultaneously
evaluated, the two threads will step over each other when writing to
_off_r.

Fortunately, for BinMem handles, making lazyGet thread-safe is simple:
just use a fresh off_r variable when deferring the call to getAt.

For BinIO handles, a race condition still exists because IO handles
contain their own mutable file pointer variable that gets clobbered in a
similar way that _off_r would. But GHC doesn't use BinIO handles anywhere
so this particular issue could be ignored for now.
TcRnMonad: Make newUnique and newUniqueSupply thread-safe

These functions are used inside a forkM'd action during the lazy
interface-file typechecking. We have to update the UniqSupply in an
atomic fashion if multiple such actions are executed concurrently.

Also remove a stale comment that alluded to using a now-commonplace
method for splitting a UniqSupply.
TidyPgm: Atomically update the name cache in tidyTopName

To pave the way for parallel --make, we need to make sure that all
modifications of shared mutable state are performed in a thread-safe
manner. This is one of such occurrences.
SysTools: Make cleanTempFiles/cleanTempDirs thread-safe

Atomically update the list of files to clean so that multiple threads
won't step over each other during cleanup.
SysTools: Make newTempName and getTempDir thread-safe

Concurrent calls to findTempName could return the same file name, and
concurrent calls to getTempDir could return different directories.
TcEnv: Atomically update wrapperRef in mkWrapperName

I haven't looked into this too deeply, but it should help mitigate any
potential race conditions.
SMP: Tweak the inline ASM of cas() on x86

*p is both read and written to and therefore should have the '+'
constraint modifier.
SMP: Tweak x86 ASM of atomic_inc() and atomic_dec()

'xadd' clobbers the status register, so specify it so in the inline ASM.
IfaceEnv: Make NameCacheUpdater a newtype

No reason why it shouldn't be.
Fix build when !defined(PROF_SPIN)

whitehole_spin is only defined when PROF_SPIN is set.
Have gc_thread.mut_spin default to locked
Don't define PROF_SPIN by default
Reimplement the RTS spin locks as ticket locks

ToDo: Update corresponding PROF_LOCK code