AO_CLEAR(&GC_allocate_lock); }
# else
# define UNCOND_LOCK() \
- { GC_ASSERT(I_DONT_HOLD_LOCK()); \
- if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \
+ { if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \
GC_lock(); }
# define UNCOND_UNLOCK() AO_CLEAR(&GC_allocate_lock)
# endif /* !GC_ASSERTIONS */
# if defined(GC_ALWAYS_MULTITHREADED) \
&& (defined(USE_PTHREAD_LOCKS) || defined(USE_SPIN_LOCK))
# define GC_need_to_lock TRUE
+# define set_need_to_lock() (void)0
# else
# if defined(GC_ALWAYS_MULTITHREADED) && !defined(CPPCHECK)
# error Runtime initialization of GC lock is needed!
# endif
# undef GC_ALWAYS_MULTITHREADED
GC_EXTERN GC_bool GC_need_to_lock;
+# define set_need_to_lock() (void)(GC_need_to_lock = TRUE)
+ /* We are multi-threaded now. */
# endif
# else /* !THREADS */
{
/* Check GC is initialized and the current thread is registered. */
GC_ASSERT(GC_lookup_thread(pthread_self()) != 0);
-
-# ifndef GC_ALWAYS_MULTITHREADED
- GC_need_to_lock = TRUE; /* We are multi-threaded now. */
-# endif
+ set_need_to_lock();
}
GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
GC_log_printf("About to start new thread from thread %p\n",
(void *)pthread_self());
# endif
-# ifndef GC_ALWAYS_MULTITHREADED
- GC_need_to_lock = TRUE;
-# endif
-
+ set_need_to_lock();
result = REAL_FUNC(pthread_create)(new_thread, attr, GC_start_routine, si);
/* Wait until child has been added to the thread table. */
{
/* Check GC is initialized and the current thread is registered. */
GC_ASSERT(GC_lookup_thread_inner(GetCurrentThreadId()) != 0);
-# ifndef GC_ALWAYS_MULTITHREADED
-# if !defined(GC_NO_THREADS_DISCOVERY) && !defined(PARALLEL_MARK)
+# if !defined(GC_ALWAYS_MULTITHREADED) && !defined(PARALLEL_MARK) \
+ && !defined(GC_NO_THREADS_DISCOVERY)
/* GC_init() does not call GC_init_parallel() in this case. */
- parallel_initialized = TRUE;
-# endif
- GC_need_to_lock = TRUE; /* We are multi-threaded now. */
+ parallel_initialized = TRUE;
# endif
+ set_need_to_lock();
}
GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
args -> start = lpStartAddress;
args -> param = lpParameter;
-# ifndef GC_ALWAYS_MULTITHREADED
- GC_need_to_lock = TRUE;
-# endif
+ set_need_to_lock();
thread_h = CreateThread(lpThreadAttributes, dwStackSize, GC_win32_start,
args, dwCreationFlags, lpThreadId);
if (thread_h == 0) GC_free(args);
args -> start = (LPTHREAD_START_ROUTINE)start_address;
args -> param = arglist;
-# ifndef GC_ALWAYS_MULTITHREADED
- GC_need_to_lock = TRUE;
-# endif
+ set_need_to_lock();
thread_h = _beginthreadex(security, stack_size,
(unsigned (__stdcall *)(void *))GC_win32_start,
args, initflag, thrdaddr);
(void *)GC_PTHREAD_PTRVAL(pthread_self()),
(long)GetCurrentThreadId());
# endif
-# ifndef GC_ALWAYS_MULTITHREADED
- GC_need_to_lock = TRUE;
-# endif
+ set_need_to_lock();
result = pthread_create(new_thread, attr, GC_pthread_start, si);
if (result) { /* failure */
# if defined(CPPCHECK) && !defined(GC_NO_THREADS_DISCOVERY)
GC_noop1((word)&GC_DllMain);
# endif
-# ifndef GC_ALWAYS_MULTITHREADED
- if (GC_win32_dll_threads) {
- GC_need_to_lock = TRUE;
+ if (GC_win32_dll_threads) {
+ set_need_to_lock();
/* Cannot intercept thread creation. Hence we don't know if */
/* other threads exist. However, client is not allowed to */
/* create other threads before collector initialization. */
/* Thus it's OK not to lock before this. */
- }
-# endif
+ }
/* Initialize thread local free lists if used. */
# if defined(THREAD_LOCAL_ALLOC)
LOCK();