Skip to content

Commit

Permalink
Showing 5 changed files with 71 additions and 20 deletions.
10 changes: 10 additions & 0 deletions lib/ruby/truffle/cext/ruby.h
Original file line number Diff line number Diff line change
@@ -206,6 +206,16 @@ void rb_alias(VALUE module, ID new_name, ID old_name);
void rb_undef_method(VALUE module, const char *name);
void rb_undef(VALUE module, ID name);

// Mutexes

VALUE rb_mutex_new(void);
VALUE rb_mutex_locked_p(VALUE mutex);
VALUE rb_mutex_trylock(VALUE mutex);
VALUE rb_mutex_lock(VALUE mutex);
VALUE rb_mutex_unlock(VALUE mutex);
VALUE rb_mutex_sleep(VALUE mutex, VALUE timeout);
VALUE rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg);

// GC

VALUE rb_gc_enable();
8 changes: 0 additions & 8 deletions spec/ruby/optional/capi/ext/jruby_truffle.h
Original file line number Diff line number Diff line change
@@ -290,14 +290,6 @@
#undef HAVE_RB_THREAD_FD_WRITABLE
#undef HAVE_RB_THREAD_WAIT_FD

#undef HAVE_RB_MUTEX_NEW
#undef HAVE_RB_MUTEX_LOCKED_P
#undef HAVE_RB_MUTEX_TRYLOCK
#undef HAVE_RB_MUTEX_LOCK
#undef HAVE_RB_MUTEX_UNLOCK
#undef HAVE_RB_MUTEX_SLEEP
#undef HAVE_RB_MUTEX_SYNCHRONIZE

#undef HAVE_RB_FD_FIX_CLOEXEC
#undef HAVE_RB_CLOEXEC_OPEN

11 changes: 0 additions & 11 deletions spec/truffle/tags/optional/capi/mutex_tags.txt

This file was deleted.

30 changes: 30 additions & 0 deletions truffle/src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
@@ -396,6 +396,36 @@ void rb_undef(VALUE module, ID name) {
truffle_invoke(RUBY_CEXT, "rb_undef", module, name);
}

// Mutexes

VALUE rb_mutex_new(void) {
return truffle_invoke(RUBY_CEXT, "rb_mutex_new");
}

VALUE rb_mutex_locked_p(VALUE mutex) {
return truffle_invoke(RUBY_CEXT, "rb_mutex_locked_p", mutex);
}

VALUE rb_mutex_trylock(VALUE mutex) {
return truffle_invoke(RUBY_CEXT, "rb_mutex_trylock", mutex);
}

VALUE rb_mutex_lock(VALUE mutex) {
return truffle_invoke(RUBY_CEXT, "rb_mutex_lock", mutex);
}

VALUE rb_mutex_unlock(VALUE mutex) {
return truffle_invoke(RUBY_CEXT, "rb_mutex_unlock", mutex);
}

VALUE rb_mutex_sleep(VALUE mutex, VALUE timeout) {
return truffle_invoke(RUBY_CEXT, "rb_mutex_sleep", mutex, timeout);
}

VALUE rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg) {
return truffle_invoke(RUBY_CEXT, "rb_mutex_synchronize", mutex, func, arg);
}

// GC

VALUE rb_gc_enable() {
32 changes: 31 additions & 1 deletion truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -215,10 +215,40 @@ def rb_undef(mod, name)
end
end

def rb_funcall(object, name, argc, args)
def rb_funcall(object, name, argc, args=[])
object.__send__(name, *args)
end

def rb_mutex_new
Mutex.new
end

def rb_mutex_locked_p(mutex)
mutex.locked?
end

def rb_mutex_trylock(mutex)
mutex.try_lock
end

def rb_mutex_lock(mutex)
mutex.lock
end

def rb_mutex_unlock(mutex)
mutex.unlock
end

def rb_mutex_sleep(mutex, timeout)
mutex.sleep(timeout)
end

def rb_mutex_synchronize(mutex, func, arg)
mutex.synchronize do
Truffle::Interop.execute(func, arg)
end
end

def rb_gc_enable
GC.enable
end

0 comments on commit e2a479e

Please sign in to comment.