Fix checks of thread-local free-lists.

* include/private/gc_priv.h, alloc.c (GC_check_fl_marks): Re-read each
pointer before following the pointed-to link, and bail out if the result is
different.  This can happen if the thread has popped the object off the
free-list.  The prototype is changed to allow re-reading the pointers.
* thread_local_alloc.c (GC_check_tls_for): Adjust the calls accordingly.
Code refactoring of GC_generic_malloc_inner (eliminate recursion)

* malloc.c (GC_generic_malloc_inner): Update "lg" value after GC_init
and GC_extend_size_map calls; add assertion on "lg" value after
GC_extend_size_map call; update "opp" and "op" values and retry
allocation instead of recursive call; replace "goto" with return
(remove "out" label).
Code refactoring of GC_check_tls_for/GC_check_fl_marks

* alloc.c (GC_check_fl_marks): Change prototype (pass pointer to
"freelist" element instead of value); do not define the function if
THREAD_LOCAL_ALLOC undefined.
* include/private/gc_priv.h (GC_check_fl_marks): Likewise.
* alloc.c (GC_check_fl_marks): Skip check if the argument points to
a special (non-pointer) value; update comment; rename "q" local
variable to "list".
* thread_local_alloc.c (GC_check_tls_for): Update code according to
GC_check_fl_marks functionality change (remove checks for special
value).
Fix GC_check_fl_marks regarding concurrent access

* alloc.c (GC_check_fl_marks): Re-read each pointer atomically before
following the pointed-to link and bail out if the result is different
(this can happen if the thread has popped the object off the
free-list); the function is a no-op if AO_load is unavailable.
Dummy merge branch 'paurkedal/fix-freelist-checks'
Include atomic_ops.h if THREAD_LOCAL_ALLOC to enable GC_check_fl_marks

* include/private/gc_priv.h: Include atomic_ops.h if GC_ASSERTIONS
and THREAD_LOCAL_ALLOC to make AO_load available to GC_check_fl_marks.
Fix GC_setspecific to prevent garbage collection inside

* specific.c (GC_setspecific): Call MALLOC_CLEAR with GC temporarily
disabled; add comment about lock.
Fix GC_remove_all_threads_but_me to cleanup thread-specific data storage

* pthread_support.c (GC_remove_all_threads_but_me): Call
GC_remove_specific after destroying thread-local list.
Fix USE_CUSTOM_SPECIFIC mode (if manually enabled) for Win32

* win32_threads.c (GC_unregister_my_thread,
GC_remove_all_threads_but_me, GC_thread_exit_proc): Invoke
GC_remove_specific (if THREAD_LOCAL_ALLOC) after destroying
thread-local list (same as in pthread_support.c).
Code refactoring of specific.c and specific.h;
cast pointers to word instead of unsigned long

* include/private/specific.h (CACHE_HASH, HASH): Add parentheses
around the argument.
* include/private/specific.h (CACHE_HASH): Remove unnecessary cast to
long.
* include/private/specific.h (HASH): Rename "n" argument to "p";
cast "p" to word instead of long; cast result to unsigned.
* include/private/specific.h (quick_thread_id, INVALID_QTID): Cast to
word instead of unsigned long.
* specific.c (GC_key_create_inner): Cast invalid_tse.next (pointer) to
word instead of unsigned long.
* include/private/specific.h (GC_slow_getspecific, GC_getspecific):
Change type of "qtid" from unsigned long to word.
* specific.c (GC_slow_getspecific): Likewise.
* include/private/specific.h (GC_getspecific): Remove "hash_val"
local variable.
* specific.c: Do not include gc_priv.h as included from
thread_local_alloc.h; do not include atomic_ops.h as included from
specific.h file.
Add assertion in GC_getspecific on qtid

* include/private/specific.h (GC_getspecific): Add assertion on "qtid"
value.
Use pthread_key for thread-local storage on FreeBSD

* include/private/thread_local_alloc.h (USE_PTHREAD_SPECIFIC): Define
for FreeBSD by default (instead of USE_CUSTOM_SPECIFIC).
Use USE_COMPILER_TLS on Cygwin

* include/private/thread_local_alloc.h (USE_COMPILER_TLS): Define for
Cygwin by default (only starting from GCC v4).
Update TODO file (add FIXME item)
Update ChangeLog file
Fix USE_CUSTOM_SPECIFIC mode (if manually enabled) for Win32

* win32_threads.c (GC_unregister_my_thread,
GC_remove_all_threads_but_me, GC_thread_exit_proc): Invoke
GC_remove_specific (if THREAD_LOCAL_ALLOC) after destroying
thread-local list (same as in pthread_support.c).
Add two missing GC_start_debugging() calls.

* dbg_mlc.c (GC_debug_generic_malloc_inner): Add GC_start_debugging() if not
done.  This fixes the missing registration of the debug header displacement.
* dbg_mlc.c (GC_debug_generic_malloc_inner_ignore_off_page): Ditto.
Merge branch 'fix-freelist-check-and-specific'
Merge branch 'freebsd-use-pthread-specific'
Update ChangeLog file