Commit cf5fe6bd authored by Jean-Claude Beaudoin's avatar Jean-Claude Beaudoin
Browse files

Add MK_GC_uninit() to achieve minimal orderly shutdown of the GC such that GC...

Add MK_GC_uninit() to achieve minimal orderly shutdown of the GC such that GC will not anymore interfere with process termination.
parent 0f5c2254
......@@ -394,6 +394,7 @@ MK_GC_API void MK_GC_CALL MK_GC_atfork_child(void);
/* Initialize the collector. Portable clients should call MK_GC_INIT() */
/* from the main program instead. */
MK_GC_API void MK_GC_CALL MK_GC_init(void);
MK_GC_API void MK_GC_CALL MK_GC_uninit(void); /* JCB */
/* General purpose allocation routines, with roughly malloc calling */
/* conv. The atomic versions promise that no relevant pointers are */
......
......@@ -1683,6 +1683,7 @@ void MK_GC_register_data_segments(void);
#ifdef THREADS
MK_GC_INNER void MK_GC_thr_init(void);
MK_GC_INNER void MK_GC_thr_uninit(void);
MK_GC_INNER void MK_GC_init_parallel(void);
#else
MK_GC_INNER MK_GC_bool MK_GC_is_static_root(ptr_t p);
......
......@@ -1225,6 +1225,15 @@ MK_GC_API void MK_GC_CALL MK_GC_init(void)
RESTORE_CANCEL(cancel_state);
}
MK_GC_API void MK_GC_CALL MK_GC_uninit(void) /* JCB */
{
MK_GC_disable();
#ifdef THREADS
MK_GC_thr_uninit();
#endif
MK_GC_is_initialized = FALSE;
}
MK_GC_API void MK_GC_CALL MK_GC_enable_incremental(void)
{
# if !defined(MK_GC_DISABLE_INCREMENTAL) && !defined(KEEP_BACK_PTRS)
......
......@@ -1147,6 +1147,15 @@ MK_GC_INNER void MK_GC_thr_init(void)
# endif
}
MK_GC_INNER void MK_GC_thr_uninit(void) /* JCB */
{
/* stop markers threads. */
MK_GC_thr_initialized = FALSE;
#ifdef PARALLEL_MARK
MK_GC_notify_all_marker();
#endif
}
/* Perform all initializations, including those that */
/* may require allocation. */
/* Called without allocation lock. */
......@@ -2036,6 +2045,11 @@ MK_GC_INNER void MK_GC_wait_marker(void)
if (pthread_cond_wait(&mark_cv, &mark_mutex) != 0) {
ABORT("pthread_cond_wait failed");
}
if ( !MK_GC_thr_initialized ) /* JCB */
{
pthread_mutex_unlock(&mark_mutex);
pthread_exit(0);
}
MK_GC_ASSERT(MK_GC_mark_lock_holder == NO_THREAD);
SET_MARK_LOCK_HOLDER;
}
......
......@@ -2094,6 +2094,7 @@ MK_GC_INNER void MK_GC_get_next_stack(char *start, char *limit,
MK_GC_release_mark_lock();
if (WaitForSingleObject(event, INFINITE) == WAIT_FAILED)
ABORT("WaitForSingleObject failed");
if ( !MK_GC_thr_initialized ) _endthreadex(0); /* JCB */
MK_GC_acquire_mark_lock();
}
......@@ -2159,6 +2160,9 @@ MK_GC_INNER void MK_GC_get_next_stack(char *start, char *limit,
INFINITE /* timeout */,
FALSE /* isAlertable */) == WAIT_FAILED)
ABORT("SignalObjectAndWait failed");
if ( !MK_GC_thr_initialized ) _endthreadex(0); /* JCB */
/* The state of mark_cv is non-signaled here again. */
if (waitcnt > 1) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment