From 5ce1564be2b748d40d47708ac6f5c7d85c7d7779 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Wed, 28 Sep 2016 16:16:32 +0300 Subject: [PATCH] [sgen] Support cementing from multiple workers --- mono/sgen/sgen-pinning.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mono/sgen/sgen-pinning.c b/mono/sgen/sgen-pinning.c index 6b2b2e33547..be803daffa7 100644 --- a/mono/sgen/sgen-pinning.c +++ b/mono/sgen/sgen-pinning.c @@ -321,8 +321,11 @@ sgen_cement_lookup_or_register (GCObject *obj) SGEN_ASSERT (5, sgen_ptr_in_nursery (obj), "Can only cement pointers to nursery objects"); if (!hash [i].obj) { - SGEN_ASSERT (5, !hash [i].count, "Cementing hash inconsistent"); - hash [i].obj = obj; + GCObject *old_obj; + old_obj = InterlockedCompareExchangePointer ((gpointer*)&hash [i].obj, obj, NULL); + /* Check if the slot was occupied by some other object */ + if (old_obj != NULL && old_obj != obj) + return FALSE; } else if (hash [i].obj != obj) { return FALSE; } @@ -330,8 +333,7 @@ sgen_cement_lookup_or_register (GCObject *obj) if (hash [i].count >= SGEN_CEMENT_THRESHOLD) return TRUE; - ++hash [i].count; - if (hash [i].count == SGEN_CEMENT_THRESHOLD) { + if (InterlockedIncrement ((gint32*)&hash [i].count) == SGEN_CEMENT_THRESHOLD) { SGEN_ASSERT (9, sgen_get_current_collection_generation () >= 0, "We can only cement objects when we're in a collection pause."); SGEN_ASSERT (9, SGEN_OBJECT_IS_PINNED (obj), "Can only cement pinned objects"); SGEN_CEMENT_OBJECT (obj); -- 2.11.4.GIT