Skip to content

Commit

Permalink
Don't lose concurrent modifications to %!conc_table
Browse files Browse the repository at this point in the history
They were just fixed to not cause MVM_oop'es by #4496,
but as @nwc10++ pointed out, we might now silently lose them. So also
add a lock such that all thread's modifications are kept.
  • Loading branch information
MasterDuke17 committed Aug 22, 2021
1 parent 5c74b40 commit 72bc562
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Perl6/Metamodel/Concretization.nqp
Expand Up @@ -3,6 +3,8 @@ role Perl6::Metamodel::Concretization {
has @!concretizations;
has %!conc_table;

my $lock := NQPLock.new;

method add_concretization($obj, $role, $concrete) {
@!concretizations[+@!concretizations] := [$role, $concrete];
nqp::scwbdisable();
Expand Down Expand Up @@ -36,13 +38,15 @@ role Perl6::Metamodel::Concretization {
}

method !rebuild_table() {
my %new_conc_table := nqp::clone(%!conc_table);
for @!concretizations {
%new_conc_table{~nqp::objectid(nqp::decont($_[0]))} := nqp::decont($_[1]);
}
nqp::scwbdisable();
%!conc_table := %new_conc_table;
nqp::scwbenable();
$lock.protect: {
my %new_conc_table := nqp::clone(%!conc_table);
for @!concretizations {
%new_conc_table{~nqp::objectid(nqp::decont($_[0]))} := nqp::decont($_[1]);
}
nqp::scwbdisable();
%!conc_table := %new_conc_table;
nqp::scwbenable();
};
}

# Returns a list where the first element is the number of roles found and the rest are actual type objects.
Expand Down

0 comments on commit 72bc562

Please sign in to comment.