/*
 * call-seq:
 *      mq.close     => nil
 *
 * Closes the underlying message queue descriptor.
 * If this descriptor had a registered notification request, the request
 * will be removed so another descriptor or process may register a
 * notification request.  Message queue descriptors are automatically
 * closed by garbage collection.
 */
static VALUE _close(VALUE self)
{
        struct posix_mq *mq;

        if (IDEMPOTENT_IO_CLOSE) { /* defined in extconf.rb */
                mq = get(self, 0);
                if (!mq || (mq->des == MQD_INVALID))
                        return Qnil;
        } else {
                mq = get(self, 1);
        }

        if (! MQ_IO_CLOSE(mq)) {
                if (mq_close(mq->des) < 0)
                        rb_sys_fail("mq_close");
        }
        mq->des = MQD_INVALID;

        return Qnil;
}