[macruby-changes] [564] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sat Sep 6 00:27:19 PDT 2008
Revision: 564
http://trac.macosforge.org/projects/ruby/changeset/564
Author: lsansonetti at apple.com
Date: 2008-09-06 00:27:17 -0700 (Sat, 06 Sep 2008)
Log Message:
-----------
making ffi closures yarv-safe
Modified Paths:
--------------
MacRuby/trunk/objc.m
MacRuby/trunk/thread_pthread.c
Modified: MacRuby/trunk/objc.m
===================================================================
--- MacRuby/trunk/objc.m 2008-09-06 05:17:51 UTC (rev 563)
+++ MacRuby/trunk/objc.m 2008-09-06 07:27:17 UTC (rev 564)
@@ -1497,10 +1497,22 @@
#define IGNORE_PRIVATE_OBJC_METHODS 1
-static void
-rb_ruby_to_objc_closure_handler(ffi_cif *cif, void *resp, void **args,
- void *userdata)
+struct rb_ruby_to_objc_closure_handler_main_ctx {
+ ffi_cif *cif;
+ void *resp;
+ void **args;
+ void *userdata;
+};
+
+static VALUE
+rb_ruby_to_objc_closure_handler_main(void *ctx)
{
+ struct rb_ruby_to_objc_closure_handler_main_ctx *_ctx =
+ (struct rb_ruby_to_objc_closure_handler_main_ctx *)ctx;
+ ffi_cif *cif = _ctx->cif;
+ void *resp = _ctx->resp;
+ void **args = _ctx->args;
+ void *userdata = _ctx->userdata;
void *rcv;
SEL sel;
ID mid;
@@ -1556,8 +1568,51 @@
type = rb_objc_method_get_type(method, cif->nargs, bs_method,
-1, buf, sizeof buf);
rb_objc_rval_to_ocval(ret, type, resp);
+
+ return Qnil;
}
+static void
+rb_ruby_to_objc_closure_handler(ffi_cif *cif, void *resp, void **args,
+ void *userdata)
+{
+ struct rb_ruby_to_objc_closure_handler_main_ctx ctx;
+
+ ctx.cif = cif;
+ ctx.resp = resp;
+ ctx.args = args;
+ ctx.userdata = userdata;
+
+ extern VALUE rb_cMutex;
+
+ if (rb_cMutex == 0) {
+ /* GL not initialized yet! */
+ rb_ruby_to_objc_closure_handler_main(&ctx);
+ }
+ else {
+#if 0
+ if (GET_VM()->main_thread == GET_THREAD()) {
+ rb_ruby_to_objc_closure_handler_main(&ctx);
+ }
+ else {
+ void native_mutex_lock(pthread_mutex_t *lock);
+ void native_mutex_unlock(pthread_mutex_t *lock);
+
+ native_mutex_lock(&GET_THREAD()->vm->global_interpreter_lock);
+ rb_ruby_to_objc_closure_handler_main(&ctx);
+ native_mutex_unlock(&GET_THREAD()->vm->global_interpreter_lock);
+ }
+#else
+ if (GET_VM()->main_thread == GET_THREAD()) {
+ rb_ruby_to_objc_closure_handler_main(&ctx);
+ }
+ else {
+ rb_thread_blocking_region(rb_ruby_to_objc_closure_handler_main, &ctx, RB_UBF_DFL, 0);
+ }
+#endif
+ }
+}
+
static void *
rb_ruby_to_objc_closure(const char *octype, unsigned arity, NODE *node)
{
Modified: MacRuby/trunk/thread_pthread.c
===================================================================
--- MacRuby/trunk/thread_pthread.c 2008-09-06 05:17:51 UTC (rev 563)
+++ MacRuby/trunk/thread_pthread.c 2008-09-06 07:27:17 UTC (rev 564)
@@ -11,8 +11,8 @@
#ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
-static void native_mutex_lock(pthread_mutex_t *lock);
-static void native_mutex_unlock(pthread_mutex_t *lock);
+void native_mutex_lock(pthread_mutex_t *lock);
+void native_mutex_unlock(pthread_mutex_t *lock);
static int native_mutex_trylock(pthread_mutex_t *lock);
static void native_mutex_initialize(pthread_mutex_t *lock);
static void native_mutex_destroy(pthread_mutex_t *lock);
@@ -23,7 +23,7 @@
static void native_cond_initialize(pthread_cond_t *cond);
static void native_cond_destroy(pthread_cond_t *cond);
-static void
+void
native_mutex_lock(pthread_mutex_t *lock)
{
int r;
@@ -32,7 +32,7 @@
}
}
-static void
+void
native_mutex_unlock(pthread_mutex_t *lock)
{
int r;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080906/7ec40f28/attachment-0001.html
More information about the macruby-changes
mailing list