Skip to content

Commit

Permalink
Added Rubinius.primitive :vm_global_serial
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jemc committed Apr 18, 2015
1 parent dfb9c9a commit fb40475
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kernel/bootstrap/rubinius.rb
Expand Up @@ -19,6 +19,11 @@ def self.extended_modules(obj)
raise PrimitiveFailure, "Rubinius.extended_modules primitive failed"
end

def self.global_serial
Rubinius.primitive :vm_global_serial
raise PrimitiveFailure, "Rubinius.vm_global_serial primitive failed"
end

def self.inc_global_serial
Rubinius.primitive :vm_inc_global_serial
raise PrimitiveFailure, "Rubinius.vm_inc_global_serial primitive failed"
Expand Down
4 changes: 4 additions & 0 deletions vm/builtin/system.cpp
Expand Up @@ -1323,6 +1323,10 @@ namespace rubinius {
return RBOOL(obj->kind_of_p(state, mod));
}

Object* System::vm_global_serial(STATE, CallFrame* calling_environment) {
return Fixnum::from(state->shared().global_serial());
}

Object* System::vm_inc_global_serial(STATE, CallFrame* calling_environment) {
if(state->shared().config.serial_debug) {
std::cout << "[Global serial increased from " << state->shared().global_serial() << "]" << std::endl;
Expand Down
4 changes: 4 additions & 0 deletions vm/builtin/system.hpp
Expand Up @@ -224,6 +224,10 @@ namespace rubinius {
// Rubinius.primitive+ :vm_object_kind_of
static Object* vm_object_kind_of(STATE, Object* obj, Module* mod);

// Return the internal global serial number, used for caching
// Rubinius.primitive :vm_global_serial
static Object* vm_global_serial(STATE, CallFrame* calling_environment);

// Increment the internal global serial number, used for caching
// Rubinius.primitive :vm_inc_global_serial
static Object* vm_inc_global_serial(STATE, CallFrame* calling_environment);
Expand Down

0 comments on commit fb40475

Please sign in to comment.