From 6d22887be14c6f543d86425545e79eff92d97714 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 27 Feb 2011 09:56:34 +0000 Subject: Do not trust locally cached mq_flags 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. --- ext/posix_mq/posix_mq.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 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 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 -- cgit v1.2.3-24-ge0c7