summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2025-08-20 17:47:17 -0700
committerJohn Hawthorn <john@hawthorn.email>2025-09-23 10:20:21 -0700
commitc05ea920cef5991ca6163d12a436a61219a234a6 (patch)
tree08965598817bf0164c8bd52c97733b0561dd3481
parent9a5e48f4144bea6fc3e8fb82cfacf4a650d9cc9b (diff)
Only set ME cached flag when unset
The same method entry may be reused in multiple caches, so once the CACHED flag is set, other Ractors may be checking for it being invalidated and we should avoid writing to the field again. I believe there are still other race conditions on how we manipulate these flags (particularly the invalidation bit), but this should make them less frequent.
-rw-r--r--method.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/method.h b/method.h
index 8328b86ee9..9e2fd24968 100644
--- a/method.h
+++ b/method.h
@@ -73,11 +73,18 @@ typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_e
#define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
#define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags |= IMEMO_FL_USER3)
#define METHOD_ENTRY_CACHED(me) ((me)->flags & IMEMO_FL_USER4)
-#define METHOD_ENTRY_CACHED_SET(me) ((me)->flags |= IMEMO_FL_USER4)
#define METHOD_ENTRY_INVALIDATED(me) ((me)->flags & IMEMO_FL_USER5)
#define METHOD_ENTRY_INVALIDATED_SET(me) ((me)->flags |= IMEMO_FL_USER5)
static inline void
+METHOD_ENTRY_CACHED_SET(rb_callable_method_entry_t *me)
+{
+ if (!METHOD_ENTRY_CACHED(me)) {
+ me->flags |= IMEMO_FL_USER4;
+ }
+}
+
+static inline void
METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
{
VM_ASSERT((int)visi >= 0 && visi <= 3);