Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Last active November 9, 2021 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterDuke17/ec8d72fafadf6305903c9ffad1eb0a9b to your computer and use it in GitHub Desktop.
Save MasterDuke17/ec8d72fafadf6305903c9ffad1eb0a9b to your computer and use it in GitHub Desktop.
diff --git src/Perl6/Metamodel/EnumHOW.nqp src/Perl6/Metamodel/EnumHOW.nqp
index 8cf0c042b..2ecd32fbc 100644
--- src/Perl6/Metamodel/EnumHOW.nqp
+++ src/Perl6/Metamodel/EnumHOW.nqp
@@ -43,6 +43,8 @@ class Perl6::Metamodel::EnumHOW
# Exportation callback for enum symbols, if any.
has $!export_callback;
+ my $lock := NQPLock.new;
+
my $archetypes := Perl6::Metamodel::Archetypes.new( :nominal(1), :composalizable(1),
:augmentable(1) );
method archetypes() {
@@ -70,6 +72,15 @@ class Perl6::Metamodel::EnumHOW
method add_enum_value($obj, $value) {
%!values{nqp::unbox_s($value.key)} := $value.value;
@!enum_value_list[+@!enum_value_list] := $value;
+ my %value_to_enum := %!value_to_enum;
+ $lock.protect: {
+ if %value_to_enum {
+ %value_to_enum{$value.value} := $value.key;
+ }
+ nqp::scwbdisable();
+ %!value_to_enum := %value_to_enum;
+ nqp::scwbenable();
+ };
}
method set_export_callback($obj, $callback) {
@@ -85,11 +96,17 @@ class Perl6::Metamodel::EnumHOW
}
method enum_from_value($obj, $value) {
- unless %!value_to_enum {
- for @!enum_value_list {
- %!value_to_enum{$_.value} := $_;
+ my %value_to_enum := %!value_to_enum;
+ $lock.protect: {
+ unless %value_to_enum {
+ for @!enum_value_list {
+ %value_to_enum{$_.value} := $_;
+ }
+ nqp::scwbdisable();
+ %!value_to_enum := %value_to_enum;
+ nqp::scwbenable();
}
- }
+ };
nqp::existskey(%!value_to_enum, $value)
?? %!value_to_enum{$value}
!! nqp::null()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment