Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c05ea92

Browse files
committed
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.
1 parent 9a5e48f commit c05ea92

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

method.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,17 @@ typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_e
7373
#define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
7474
#define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags |= IMEMO_FL_USER3)
7575
#define METHOD_ENTRY_CACHED(me) ((me)->flags & IMEMO_FL_USER4)
76-
#define METHOD_ENTRY_CACHED_SET(me) ((me)->flags |= IMEMO_FL_USER4)
7776
#define METHOD_ENTRY_INVALIDATED(me) ((me)->flags & IMEMO_FL_USER5)
7877
#define METHOD_ENTRY_INVALIDATED_SET(me) ((me)->flags |= IMEMO_FL_USER5)
7978

79+
static inline void
80+
METHOD_ENTRY_CACHED_SET(rb_callable_method_entry_t *me)
81+
{
82+
if (!METHOD_ENTRY_CACHED(me)) {
83+
me->flags |= IMEMO_FL_USER4;
84+
}
85+
}
86+
8087
static inline void
8188
METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
8289
{

0 commit comments

Comments
 (0)