X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fsgen%2Fsgen-workers.c;h=f1212c658c4c755954fba3d3927e62742cfe836e;hb=7efe0456a36a4f95b277720c28a63580ff4f29bb;hp=4f096f697f04b0b7d69695a2074de740ae4c7256;hpb=2901e91c9d60c0556f993a474b0d582dc53a84f2;p=mono.git diff --git a/mono/sgen/sgen-workers.c b/mono/sgen/sgen-workers.c index 4f096f697f0..f1212c658c4 100644 --- a/mono/sgen/sgen-workers.c +++ b/mono/sgen/sgen-workers.c @@ -31,6 +31,7 @@ #include "mono/sgen/sgen-client.h" static int workers_num; +static volatile gboolean forced_stop; static WorkerData *workers_data; static SgenSectionGrayQueue workers_distribute_gray_queue; @@ -122,18 +123,14 @@ worker_try_finish (void) /* We are the last thread to go to sleep. */ } while (!set_state (old_state, STATE_NOT_WORKING)); -} -static gboolean -collection_needs_workers (void) -{ - return sgen_collection_is_concurrent (); + binary_protocol_worker_finish (sgen_timestamp (), forced_stop); } void -sgen_workers_enqueue_job (SgenThreadPoolJob *job) +sgen_workers_enqueue_job (SgenThreadPoolJob *job, gboolean enqueue) { - if (!collection_needs_workers ()) { + if (!enqueue) { job->func (NULL, job); sgen_thread_pool_job_free (job); return; @@ -196,7 +193,7 @@ init_private_gray_queue (WorkerData *data) static void thread_pool_init_func (void *data_untyped) { - WorkerData *data = data_untyped; + WorkerData *data = (WorkerData *)data_untyped; SgenMajorCollector *major = sgen_get_major_collector (); sgen_client_thread_register_worker (); @@ -216,7 +213,7 @@ continue_idle_func (void) static void marker_idle_func (void *data_untyped) { - WorkerData *data = data_untyped; + WorkerData *data = (WorkerData *)data_untyped; SGEN_ASSERT (0, continue_idle_func (), "Why are we called when we're not supposed to work?"); SGEN_ASSERT (0, sgen_concurrent_collection_in_progress (), "The worker should only mark in concurrent collections."); @@ -226,12 +223,12 @@ marker_idle_func (void *data_untyped) SGEN_ASSERT (0, workers_state != STATE_NOT_WORKING, "How did we get from WORK ENQUEUED to NOT WORKING?"); } - if (!sgen_gray_object_queue_is_empty (&data->private_gray_queue) || workers_get_work (data)) { + if (!forced_stop && (!sgen_gray_object_queue_is_empty (&data->private_gray_queue) || workers_get_work (data))) { ScanCopyContext ctx = CONTEXT_FROM_OBJECT_OPERATIONS (idle_func_object_ops, &data->private_gray_queue); SGEN_ASSERT (0, !sgen_gray_object_queue_is_empty (&data->private_gray_queue), "How is our gray queue empty if we just got work?"); - sgen_drain_gray_stack (32, ctx); + sgen_drain_gray_stack (ctx); } else { worker_try_finish (); } @@ -254,7 +251,7 @@ init_distribute_gray_queue (void) void sgen_workers_init_distribute_gray_queue (void) { - SGEN_ASSERT (0, sgen_get_major_collector ()->is_concurrent && collection_needs_workers (), + SGEN_ASSERT (0, sgen_get_major_collector ()->is_concurrent, "Why should we init the distribute gray queue if we don't need it?"); init_distribute_gray_queue (); } @@ -263,7 +260,7 @@ void sgen_workers_init (int num_workers) { int i; - void **workers_data_ptrs = alloca(num_workers * sizeof(void *)); + void **workers_data_ptrs = (void **)alloca(num_workers * sizeof(void *)); if (!sgen_get_major_collector ()->is_concurrent) { sgen_thread_pool_init (num_workers, thread_pool_init_func, NULL, NULL, NULL); @@ -274,7 +271,7 @@ sgen_workers_init (int num_workers) workers_num = num_workers; - workers_data = sgen_alloc_internal_dynamic (sizeof (WorkerData) * num_workers, INTERNAL_MEM_WORKER_DATA, TRUE); + workers_data = (WorkerData *)sgen_alloc_internal_dynamic (sizeof (WorkerData) * num_workers, INTERNAL_MEM_WORKER_DATA, TRUE); memset (workers_data, 0, sizeof (WorkerData) * num_workers); init_distribute_gray_queue (); @@ -288,11 +285,19 @@ sgen_workers_init (int num_workers) } void -sgen_workers_start_all_workers (SgenObjectOperations *object_ops) +sgen_workers_stop_all_workers (void) { - if (!collection_needs_workers ()) - return; + forced_stop = TRUE; + sgen_thread_pool_wait_for_all_jobs (); + sgen_thread_pool_idle_wait (); + SGEN_ASSERT (0, workers_state == STATE_NOT_WORKING, "Can only signal enqueue work when in no work state"); +} + +void +sgen_workers_start_all_workers (SgenObjectOperations *object_ops) +{ + forced_stop = FALSE; idle_func_object_ops = object_ops; mono_memory_write_barrier (); @@ -304,9 +309,6 @@ sgen_workers_join (void) { int i; - if (!collection_needs_workers ()) - return; - sgen_thread_pool_wait_for_all_jobs (); sgen_thread_pool_idle_wait (); SGEN_ASSERT (0, workers_state == STATE_NOT_WORKING, "Can only signal enqueue work when in no work state"); @@ -318,6 +320,28 @@ sgen_workers_join (void) SGEN_ASSERT (0, sgen_gray_object_queue_is_empty (&workers_data [i].private_gray_queue), "Why is there still work left to do?"); } +/* + * Can only be called if the workers are stopped. + * If we're stopped, there are also no pending jobs. + */ +gboolean +sgen_workers_have_idle_work (void) +{ + int i; + + SGEN_ASSERT (0, forced_stop && sgen_workers_all_done (), "Checking for idle work should only happen if the workers are stopped."); + + if (!sgen_section_gray_queue_is_empty (&workers_distribute_gray_queue)) + return TRUE; + + for (i = 0; i < workers_num; ++i) { + if (!sgen_gray_object_queue_is_empty (&workers_data [i].private_gray_queue)) + return TRUE; + } + + return FALSE; +} + gboolean sgen_workers_all_done (void) { @@ -331,13 +355,6 @@ sgen_workers_are_working (void) return state_is_working_or_enqueued (workers_state); } -void -sgen_workers_wait (void) -{ - sgen_thread_pool_idle_wait (); - SGEN_ASSERT (0, sgen_workers_all_done (), "Why are the workers not done after we wait for them?"); -} - SgenSectionGrayQueue* sgen_workers_get_distribute_section_gray_queue (void) {