From 5849a3ca8e0691a7f39c5cdbfc09fc34ee4da308 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 20 Feb 2010 14:46:04 -0800 Subject: do not release GVL when unlinking/opening Since the message queue is not actually on a (slow) block device, it's unlikely to block in a way where other tasks may be scheduled by the kernel. So avoid complicating things and unnecessary task switching and assume mq_open/mq_unlink can be executed as fast as the CPU/memory subsystems allows. --- ext/posix_mq/posix_mq.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'ext/posix_mq/posix_mq.c') diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c index 8a016bf..5b7a3ed 100644 --- a/ext/posix_mq/posix_mq.c +++ b/ext/posix_mq/posix_mq.c @@ -147,7 +147,7 @@ static struct timespec *convert_timeout(struct timespec *dest, VALUE time) return dest; } -/* runs without GVL */ +/* (may) run without GVL */ static VALUE xopen(void *ptr) { struct open_args *x = ptr; @@ -187,14 +187,6 @@ static VALUE xrecv(void *ptr) return (VALUE)mq_receive(x->des, x->msg_ptr, x->msg_len, &x->msg_prio); } -/* runs without GVL, path resolution may be slow */ -static VALUE xunlink(void *ptr) -{ - VALUE name = (VALUE)ptr; - - return (VALUE)mq_unlink(RSTRING_PTR(name)); -} - /* called by GC */ static void mark(void *ptr) { @@ -361,7 +353,7 @@ static VALUE init(int argc, VALUE *argv, VALUE self) RSTRING_PTR(rb_inspect(attr))); } - mq->des = (mqd_t)rb_thread_blocking_region(xopen, &x, RUBY_UBF_IO, 0); + mq->des = (mqd_t)xopen(&x); if (mq->des == MQD_INVALID) rb_sys_fail("mq_open"); @@ -382,12 +374,11 @@ static VALUE init(int argc, VALUE *argv, VALUE self) static VALUE s_unlink(VALUE self, VALUE name) { mqd_t rv; - void *ptr = (void *)name; if (TYPE(name) != T_STRING) rb_raise(rb_eArgError, "argument must be a string"); - rv = (mqd_t)rb_thread_blocking_region(xunlink, ptr, RUBY_UBF_IO, 0); + rv = mq_unlink(RSTRING_PTR(name)); if (rv == MQD_INVALID) rb_sys_fail("mq_unlink"); @@ -408,11 +399,10 @@ static VALUE _unlink(VALUE self) { struct posix_mq *mq = get(self, 0); mqd_t rv; - void *ptr = (void *)mq->name; assert(TYPE(mq->name) == T_STRING && "mq->name is not a string"); - rv = (mqd_t)rb_thread_blocking_region(xunlink, ptr, RUBY_UBF_IO, 0); + rv = mq_unlink(RSTRING_PTR(mq->name)); if (rv == MQD_INVALID) rb_sys_fail("mq_unlink"); -- cgit v1.2.3-24-ge0c7