+ mono_os_mutex_lock (&finished_lock);
+
+ for (i = 0; i < active_workers_num; i++) {
+ if (state_is_working_or_enqueued (workers_data [i].state))
+ working++;
+ }
+
+ if (working == 1) {
+ SgenWorkersFinishCallback callback = finish_callback;
+ SGEN_ASSERT (0, idle_func_object_ops == idle_func_object_ops_nopar, "Why are we finishing with parallel context");
+ /* We are the last one left. Enqueue preclean job if we have one and awake everybody */
+ SGEN_ASSERT (0, data->state != STATE_NOT_WORKING, "How did we get from doing idle work to NOT WORKING without setting it ourselves?");
+ if (callback) {
+ finish_callback = NULL;
+ callback ();
+ worker_awakenings = 0;
+ /* Make sure each worker has a chance of seeing the enqueued jobs */
+ sgen_workers_ensure_awake ();
+ SGEN_ASSERT (0, data->state == STATE_WORK_ENQUEUED, "Why did we fail to set our own state to ENQUEUED");
+ goto work_available;
+ }
+ }
+