Skip to content

Commit fb40475

Browse files
committedApr 18, 2015
Added Rubinius.primitive :vm_global_serial
This is the read-only version of :vm_inc_global_serial, returning the current value of the serial without modification. This is useful for implementing caches in Ruby-space that are to be invalidated when the global serial is incremented. (That is, when constants are assigned or included into modules).
1 parent dfb9c9a commit fb40475

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed
 

Diff for: ‎kernel/bootstrap/rubinius.rb

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def self.extended_modules(obj)
1919
raise PrimitiveFailure, "Rubinius.extended_modules primitive failed"
2020
end
2121

22+
def self.global_serial
23+
Rubinius.primitive :vm_global_serial
24+
raise PrimitiveFailure, "Rubinius.vm_global_serial primitive failed"
25+
end
26+
2227
def self.inc_global_serial
2328
Rubinius.primitive :vm_inc_global_serial
2429
raise PrimitiveFailure, "Rubinius.vm_inc_global_serial primitive failed"

Diff for: ‎vm/builtin/system.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,10 @@ namespace rubinius {
13231323
return RBOOL(obj->kind_of_p(state, mod));
13241324
}
13251325

1326+
Object* System::vm_global_serial(STATE, CallFrame* calling_environment) {
1327+
return Fixnum::from(state->shared().global_serial());
1328+
}
1329+
13261330
Object* System::vm_inc_global_serial(STATE, CallFrame* calling_environment) {
13271331
if(state->shared().config.serial_debug) {
13281332
std::cout << "[Global serial increased from " << state->shared().global_serial() << "]" << std::endl;

Diff for: ‎vm/builtin/system.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ namespace rubinius {
224224
// Rubinius.primitive+ :vm_object_kind_of
225225
static Object* vm_object_kind_of(STATE, Object* obj, Module* mod);
226226

227+
// Return the internal global serial number, used for caching
228+
// Rubinius.primitive :vm_global_serial
229+
static Object* vm_global_serial(STATE, CallFrame* calling_environment);
230+
227231
// Increment the internal global serial number, used for caching
228232
// Rubinius.primitive :vm_inc_global_serial
229233
static Object* vm_inc_global_serial(STATE, CallFrame* calling_environment);

0 commit comments

Comments
 (0)
Please sign in to comment.