about summary refs log tree commit homepage
path: root/ext/posix_mq/posix_mq.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-02-20 14:46:04 -0800
committerEric Wong <normalperson@yhbt.net>2010-02-20 14:46:04 -0800
commit5849a3ca8e0691a7f39c5cdbfc09fc34ee4da308 (patch)
treeec8136d1a7c9fd8916503697b1caab122b15e8e8 /ext/posix_mq/posix_mq.c
parenta90d0f97c9eb5d9683af09b60ef7af9e94a255c3 (diff)
downloadruby_posix_mq-5849a3ca8e0691a7f39c5cdbfc09fc34ee4da308.tar.gz
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.
Diffstat (limited to 'ext/posix_mq/posix_mq.c')
-rw-r--r--ext/posix_mq/posix_mq.c18
1 files changed, 4 insertions, 14 deletions
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");