2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

Avoid C preprocessor trick where macro has the same name as a function.

In C, one can do preprocessor tricks by making a macro expansion include
the macro's own name.  We actually used this in the tree to automatically
provide function arguments, e.g.:

    int f(int x, const char *file, int line);
    #define f(x) f(x, __FILE__, __LINE__)

...

    f(1);    /* Expands to a call like f(1, __FILE__, __LINE__); */

However it's somewhat confusing, so this commit stops using that trick.

Reported-by: Ed Maste <emaste@freebsd.org>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ed Maste <emaste@freebsd.org>
This commit is contained in:
Ben Pfaff
2013-07-29 15:24:45 -07:00
parent 74cc3969af
commit 5453ae2067
9 changed files with 70 additions and 56 deletions

View File

@@ -30,11 +30,6 @@
#include "timeval.h"
#include "vlog.h"
#undef poll_fd_wait
#undef poll_timer_wait
#undef poll_timer_wait_until
#undef poll_immediate_wake
VLOG_DEFINE_THIS_MODULE(poll_loop);
COVERAGE_DEFINE(poll_fd_wait);
@@ -63,10 +58,11 @@ static struct poll_loop *poll_loop(void);
* is affected. The event will need to be re-registered after poll_block() is
* called if it is to persist.
*
* Ordinarily the 'where' argument is supplied automatically; see poll-loop.h
* for more information. */
* ('where' is used in debug logging. Commonly one would use poll_fd_wait() to
* automatically provide the caller's source file and line number for
* 'where'.) */
void
poll_fd_wait(int fd, short int events, const char *where)
poll_fd_wait_at(int fd, short int events, const char *where)
{
struct poll_loop *loop = poll_loop();
@@ -93,10 +89,11 @@ poll_fd_wait(int fd, short int events, const char *where)
* is affected. The timer will need to be re-registered after poll_block() is
* called if it is to persist.
*
* Ordinarily the 'where' argument is supplied automatically; see poll-loop.h
* for more information. */
* ('where' is used in debug logging. Commonly one would use poll_timer_wait()
* to automatically provide the caller's source file and line number for
* 'where'.) */
void
poll_timer_wait(long long int msec, const char *where)
poll_timer_wait_at(long long int msec, const char *where)
{
long long int now = time_msec();
long long int when;
@@ -112,7 +109,7 @@ poll_timer_wait(long long int msec, const char *where)
when = LLONG_MAX;
}
poll_timer_wait_until(when, where);
poll_timer_wait_until_at(when, where);
}
/* Causes the following call to poll_block() to wake up when the current time,
@@ -124,10 +121,11 @@ poll_timer_wait(long long int msec, const char *where)
* is affected. The timer will need to be re-registered after poll_block() is
* called if it is to persist.
*
* Ordinarily the 'where' argument is supplied automatically; see poll-loop.h
* for more information. */
* ('where' is used in debug logging. Commonly one would use
* poll_timer_wait_until() to automatically provide the caller's source file
* and line number for 'where'.) */
void
poll_timer_wait_until(long long int when, const char *where)
poll_timer_wait_until_at(long long int when, const char *where)
{
struct poll_loop *loop = poll_loop();
if (when < loop->timeout_when) {
@@ -139,12 +137,13 @@ poll_timer_wait_until(long long int when, const char *where)
/* Causes the following call to poll_block() to wake up immediately, without
* blocking.
*
* Ordinarily the 'where' argument is supplied automatically; see poll-loop.h
* for more information. */
* ('where' is used in debug logging. Commonly one would use
* poll_immediate_wake() to automatically provide the caller's source file and
* line number for 'where'.) */
void
poll_immediate_wake(const char *where)
poll_immediate_wake_at(const char *where)
{
poll_timer_wait(0, where);
poll_timer_wait_at(0, where);
}
/* Logs, if appropriate, that the poll loop was awakened by an event