Skip to content

Commit

Permalink
Add argument to planner hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-frigo committed May 25, 2015
1 parent 94ef591 commit 0e53e3e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
9 changes: 6 additions & 3 deletions api/apiplan.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@

static X(before_planner_hook_t) before_planner_hook = 0;
static X(after_planner_hook_t) after_planner_hook = 0;
static void *planner_hook_arg = 0;

void X(set_planner_hooks)(X(before_planner_hook_t) before,
X(after_planner_hook_t) after)
X(after_planner_hook_t) after,
void *arg)
{
before_planner_hook = before;
after_planner_hook = after;
planner_hook_arg = arg;
}

static plan *mkplan0(planner *plnr, unsigned flags,
Expand Down Expand Up @@ -99,7 +102,7 @@ apiplan *X(mkapiplan)(int sign, unsigned flags, problem *prb)
double pcost = 0;

if (before_planner_hook)
before_planner_hook();
before_planner_hook(planner_hook_arg);

plnr = X(the_planner)();

Expand Down Expand Up @@ -175,7 +178,7 @@ apiplan *X(mkapiplan)(int sign, unsigned flags, problem *prb)
#endif

if (after_planner_hook)
after_planner_hook();
after_planner_hook(planner_hook_arg);

return p;
}
Expand Down
11 changes: 6 additions & 5 deletions api/fftw3.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ struct fftw_iodim64_do_not_use_me {

typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *);
typedef int (*fftw_read_char_func_do_not_use_me)(void *);
typedef void (*fftw_before_planner_hook_do_not_use_me)(void);
typedef void (*fftw_after_planner_hook_do_not_use_me)(void);
typedef void (*fftw_before_planner_hook_do_not_use_me)(void *arg);
typedef void (*fftw_after_planner_hook_do_not_use_me)(void *arg);

/*
huge second-order macro that defines prototypes for all API
Expand Down Expand Up @@ -136,9 +136,10 @@ typedef fftw_before_planner_hook_do_not_use_me X(before_planner_hook_t); \
typedef fftw_after_planner_hook_do_not_use_me X(after_planner_hook_t); \
\
FFTW_EXTERN void X(set_planner_hooks)(X(before_planner_hook_t) before, \
X(after_planner_hook_t) after); \
\
FFTW_EXTERN void X(execute)(const X(plan) p); \
X(after_planner_hook_t) after, \
void *arg); \
\
FFTW_EXTERN void X(execute)(const X(plan) p); \
\
FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \
C *in, C *out, int sign, unsigned flags); \
Expand Down
10 changes: 6 additions & 4 deletions tests/fftw-bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ int can_do(bench_problem *p)

static int before_planner_hook_called = 0;
static int after_planner_hook_called = 0;
static void before_planner_hook(void)
static void before_planner_hook(void *arg)
{
before_planner_hook_called = 1;
BENCH_ASSERT(arg == &before_planner_hook_called);
}
static void after_planner_hook(void)
static void after_planner_hook(void *arg)
{
after_planner_hook_called = 1;
BENCH_ASSERT(arg == &before_planner_hook_called);
}

void setup(bench_problem *p)
Expand Down Expand Up @@ -235,7 +237,7 @@ void setup(bench_problem *p)
#endif

if (setup_hooks)
FFTW(set_planner_hooks(before_planner_hook, after_planner_hook));
FFTW(set_planner_hooks(before_planner_hook, after_planner_hook, &before_planner_hook_called));

before_planner_hook_called = 0;
after_planner_hook_called = 0;
Expand All @@ -250,7 +252,7 @@ void setup(bench_problem *p)
BENCH_ASSERT(setup_hooks == after_planner_hook_called);

/* do something different with hooks next time */
FFTW(set_planner_hooks(0, 0));
FFTW(set_planner_hooks(0, 0, 0));
setup_hooks = 1 - setup_hooks;

{
Expand Down

0 comments on commit 0e53e3e

Please sign in to comment.