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>2011-02-27 09:56:34 +0000
committerEric Wong <normalperson@yhbt.net>2011-02-27 11:02:45 +0000
commit6d22887be14c6f543d86425545e79eff92d97714 (patch)
tree8be0ee7cb7e31eb9dbb136a3c6777e6811051a7b /ext/posix_mq/posix_mq.c
parentc02944edaed780bb20ad98ecdd11463d945b36ca (diff)
downloadruby_posix_mq-6d22887be14c6f543d86425545e79eff92d97714.tar.gz
These flags can be changed in the parent or child
process, so we will always have to run mq_getattr()
to check it.  This removes the GVL-keeping non-blocking
optimizations but we'll gain some soon.
Diffstat (limited to 'ext/posix_mq/posix_mq.c')
-rw-r--r--ext/posix_mq/posix_mq.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c
index 0d08698..0d96c08 100644
--- a/ext/posix_mq/posix_mq.c
+++ b/ext/posix_mq/posix_mq.c
@@ -529,11 +529,7 @@ static VALUE _send(int argc, VALUE *argv, VALUE self)
         x.timeout = convert_timeout(&expire, timeout);
         x.msg_prio = NIL_P(prio) ? 0 : NUM2UINT(prio);
 
-        if (mq->attr.mq_flags & O_NONBLOCK)
-                rv = (mqd_t)xsend(&x);
-        else
-                rv = (mqd_t)rb_thread_blocking_region(xsend, &x,
-                                                      RUBY_UBF_IO, 0);
+        rv = (mqd_t)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
         if (rv == MQD_INVALID)
                 rb_sys_fail("mq_send");
 
@@ -558,12 +554,7 @@ static VALUE send0(VALUE self, VALUE buffer)
         x.timeout = NULL;
         x.msg_prio = 0;
 
-        if (mq->attr.mq_flags & O_NONBLOCK)
-                rv = (mqd_t)xsend(&x);
-        else
-                rv = (mqd_t)rb_thread_blocking_region(xsend, &x,
-                                                      RUBY_UBF_IO, 0);
-
+        rv = (mqd_t)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
         if (rv == MQD_INVALID)
                 rb_sys_fail("mq_send");
 
@@ -667,12 +658,7 @@ static VALUE _receive(int wantarray, int argc, VALUE *argv, VALUE self)
         x.msg_len = (size_t)mq->attr.mq_msgsize;
         x.des = mq->des;
 
-        if (mq->attr.mq_flags & O_NONBLOCK) {
-                r = (ssize_t)xrecv(&x);
-        } else {
-                r = (ssize_t)rb_thread_blocking_region(xrecv, &x,
-                                                       RUBY_UBF_IO, 0);
-        }
+        r = (ssize_t)rb_thread_blocking_region(xrecv, &x, RUBY_UBF_IO, 0);
         if (r < 0)
                 rb_sys_fail("mq_receive");
 
@@ -940,10 +926,12 @@ static VALUE setnotify(VALUE self, VALUE arg)
  *
  * Returns the current non-blocking state of the message queue descriptor.
  */
-static VALUE getnonblock(VALUE self)
+static VALUE nonblock_p(VALUE self)
 {
         struct posix_mq *mq = get(self, 1);
 
+        if (mq_getattr(mq->des, &mq->attr) < 0)
+                rb_sys_fail("mq_getattr");
         return mq->attr.mq_flags & O_NONBLOCK ? Qtrue : Qfalse;
 }
 
@@ -1017,7 +1005,7 @@ void Init_posix_mq_ext(void)
         rb_define_method(cPOSIX_MQ, "nonblock=", setnonblock, 1);
         rb_define_method(cPOSIX_MQ, "notify_exec", setnotify_exec, 2);
         rb_define_method(cPOSIX_MQ, "notify_cleanup", notify_cleanup, 0);
-        rb_define_method(cPOSIX_MQ, "nonblock?", getnonblock, 0);
+        rb_define_method(cPOSIX_MQ, "nonblock?", nonblock_p, 0);
 #ifdef MQD_TO_FD
         rb_define_method(cPOSIX_MQ, "to_io", to_io, 0);
 #endif