[sgen] Implement work context for thread pool threads
[mono.git] / mono / sgen / sgen-simple-nursery.c
index 39d08abcf16027b60b884376a02acbc9a2517ea3..5d39368402b133d4e6c0a0bd2adcc22ad611c2af 100644 (file)
@@ -19,7 +19,9 @@
 #include "mono/sgen/sgen-protocol.h"
 #include "mono/sgen/sgen-layout-stats.h"
 #include "mono/sgen/sgen-client.h"
+#include "mono/sgen/sgen-workers.h"
 #include "mono/utils/mono-memory-model.h"
+#include "mono/utils/mono-proclib.h"
 
 static inline GCObject*
 alloc_for_promotion (GCVTable vtable, GCObject *obj, size_t objsize, gboolean has_references)
@@ -130,6 +132,9 @@ fill_serial_with_concurrent_major_ops (SgenObjectOperations *ops)
 void
 sgen_simple_nursery_init (SgenMinorCollector *collector, gboolean parallel)
 {
+       if (mono_cpu_count () <= 1)
+               parallel = FALSE;
+
        collector->is_split = FALSE;
        collector->is_parallel = parallel;
 
@@ -146,6 +151,13 @@ sgen_simple_nursery_init (SgenMinorCollector *collector, gboolean parallel)
        fill_serial_ops (&collector->serial_ops);
        fill_serial_with_concurrent_major_ops (&collector->serial_ops_with_concurrent_major);
        fill_parallel_ops (&collector->parallel_ops);
+
+       /*
+        * The nursery worker context is created first so it will have priority over
+        * concurrent mark and concurrent sweep.
+        */
+       if (parallel)
+               sgen_workers_create_context (GENERATION_NURSERY, mono_cpu_count ());
 }