mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Jackson <pj@sgi.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: cw@f00f.org, dcn@sgi.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] add wait_event_interruptible_exclusive() macro
Date: Tue, 22 Jun 2004 06:35:37 -0700	[thread overview]
Message-ID: <20040622063537.33282647.pj@sgi.com> (raw)
In-Reply-To: <20040622122948.GA2038@infradead.org>

Christoph wrote:
> In this case a macro is the only sensible way.  Check how the arguments
> are used in wait_event_*

Are you referring to such usages as the "&wq" in this line:

>	add_wait_queue_exclusive(&wq, &__wait);

If so, then yes, a macro is needed.  This is a poor man's implicit pass
by reference.  In straight C, not using macros, saying "foo(x)" pushes
the value of 'x' on the stack, not the address of 'x'.  This macro
pushes the _address_ of 'x' on the stack (x == wq), but doesn't require
the "address of" operator, "&", as in foo(&x), to be explicitly coded. 
Hence, straight C is insufficient to the task.

I don't know if it applies in this case, but one can mix macros with
inlines, to get both this implicit pass by reference, and get some
type checking on the arguments.  See my dreaded cpumask patch, in the
latest *-mm patch series, for many examples.

They look like:

#define foo(x) __foo(&(x))

static inline void __foo(int *xp)		\
{						\
	printk("addr of x is %p\n", xp);	\
}

This both provides implicit pass by reference, and checks that the
argument and return types are as intended (to within the range of
C's automatic type conversions ;).

Be aware that I am engaging in drive-by-commenting here, which is
commenting on a phrase that jumped out at me, without any effort to
look around at the larger picture.  Damage due to collateral fire is
not uncommon in such cases ;).

-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

  reply	other threads:[~2004-06-22 13:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-18 15:12 Dean Nelson
2004-06-22 12:01 ` Chris Wedgwood
2004-06-22 12:27   ` Dean Nelson
2004-06-22 12:29   ` Christoph Hellwig
2004-06-22 13:35     ` Paul Jackson [this message]
2004-06-22 14:35       ` Christoph Hellwig

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=20040622063537.33282647.pj@sgi.com \
    --to=pj@sgi.com \
    --cc=cw@f00f.org \
    --cc=dcn@sgi.com \
    --cc=hch@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®