All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: "Davi E. M. Arnaut" <davi@haxent.com.br>
Cc: Davide Libenzi <davidel@xmailserver.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: + signalfd-retrieve-multiple-signals-with-one-read-call.patch added to -mm tree
Date: Mon, 21 May 2007 23:25:51 +0400	[thread overview]
Message-ID: <20070521192551.GA153@tv-sign.ru> (raw)

A couple of very minor nits,

> +static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, siginfo_t *info,
> +				int nonblock)
> +{
> +	int locked;
> +	ssize_t ret;
> +	struct signalfd_lockctx lk;
> +	DECLARE_WAITQUEUE(wait, current);
> +
> +	locked = signalfd_lock(ctx, &lk);
> +	if (!locked)
> +		return 0;
> +
> +	ret = dequeue_signal(lk.tsk, &ctx->sigmask, info);
> +	switch (ret) {
> +	case 0:
> +		if (!nonblock)
> +			break;
> +		ret = -EAGAIN;
> +	default:
> +		signalfd_unlock(&lk);
> +		return ret;
> +	}
> +
> +	add_wait_queue(&ctx->wqh, &wait);
> +	for (;;) {
> +		set_current_state(TASK_INTERRUPTIBLE);
> +		ret = dequeue_signal(lk.tsk, &ctx->sigmask, info);
> +		if (ret != 0)
> +			break;
> +		if (signal_pending(current)) {
> +			ret = -ERESTARTSYS;
> +			break;
> +		}
> +		signalfd_unlock(&lk);

The locking looks a bit overcomplicated. We don't need signalfd_lock() to
check ret != 0 or signal_pending(), we can drop it earlier. This way we
always leave the loop in "unlocked" state.

> +		schedule();
> +		locked = signalfd_lock(ctx, &lk);
> +		if (unlikely(!locked)) {
> +			/*
> +			 * Let the caller read zero byte, ala socket
> +			 * recv() when the peer disconnect. This test
> +			 * must be done before doing a dequeue_signal(),
> +			 * because if the sighand has been orphaned,
> +			 * the dequeue_signal() call is going to crash.
> +			 */

Imho, the comment is a bit confusing. dequeue_signal() needs ->siglock
even if signalfd_ctx is not orphaned.

> +			 ret = 0;
> +			 break;
> +		}
> +	}
> +
> +	remove_wait_queue(&ctx->wqh, &wait);
> +	__set_current_state(TASK_RUNNING);
> +
> +	if (likely(locked))
> +		signalfd_unlock(&lk);
> +
> +	return ret;
> +}

IOW, how about this?

	static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, siginfo_t *info,
					int nonblock)
	{
		ssize_t ret;
		struct signalfd_lockctx lk;
		DECLARE_WAITQUEUE(wait, current);

		if (!signalfd_lock(ctx, &lk))
			return 0;

		ret = dequeue_signal(lk.tsk, &ctx->sigmask, info);
		switch (ret) {
		case 0:
			if (!nonblock)
				break;
			ret = -EAGAIN;
		default:
			signalfd_unlock(&lk);
			return ret;
		}

		add_wait_queue(&ctx->wqh, &wait);
		for (;;) {
			set_current_state(TASK_INTERRUPTIBLE);
			ret = dequeue_signal(lk.tsk, &ctx->sigmask, info);
			signalfd_unlock(&lk);

			if (ret != 0)
				break;

			ret = -ERESTARTSYS;
			if (signal_pending(current))
				break;

			schedule();

			ret = 0;
			if (!signalfd_lock(ctx, &lk))
				break;
		}

		remove_wait_queue(&ctx->wqh, &wait);
		__set_current_state(TASK_RUNNING);

		return ret;
	}

Oleg.


             reply	other threads:[~2007-05-21 19:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-21 19:25 Oleg Nesterov [this message]
2007-05-21 20:16 ` + signalfd-retrieve-multiple-signals-with-one-read-call.patch added to -mm tree Davide Libenzi
2007-05-21 20:41   ` Davi Arnaut
  -- strict thread matches above, loose matches on Subject: below --
2007-05-21  4:02 akpm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070521192551.GA153@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=akpm@linux-foundation.org \
    --cc=davi@haxent.com.br \
    --cc=davidel@xmailserver.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.