Skip to content

Commit

Permalink
Merge pull request #411 from circonus-labs/lua_initiate_once
Browse files Browse the repository at this point in the history
Support different initiation on 'once' invocations.
  • Loading branch information
postwait committed Nov 3, 2017
2 parents d6d28ff + 1aaee50 commit 2054dcc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/modules/lua_check.c
Expand Up @@ -1057,8 +1057,8 @@ int_cl_free(void *vcl) {
}

static int
noit_lua_initiate(noit_module_t *self, noit_check_t *check,
noit_check_t *cause) {
noit_lua_initiate_ex(noit_module_t *self, noit_check_t *check,
noit_check_t *cause, mtev_boolean once) {
LMC_DECL(L, self, object);
/* deal with unused warning */
(void)L;
Expand Down Expand Up @@ -1122,7 +1122,8 @@ noit_lua_initiate(noit_module_t *self, noit_check_t *check,
noit_lua_setup_check(ri->coro_state, ci->cause);
else
lua_pushnil(ri->coro_state);
mtev_lua_lmc_resume(lmc, ri, 3);
lua_pushboolean(ri->coro_state, once);
mtev_lua_lmc_resume(lmc, ri, 4);
return 0;

fail:
Expand All @@ -1131,11 +1132,24 @@ noit_lua_initiate(noit_module_t *self, noit_check_t *check,
return -1;
}

static int
noit_lua_initiate(noit_module_t *self, noit_check_t *check,
noit_check_t *cause) {
return noit_lua_initiate_ex(self, check, cause, mtev_false);
}

static int
noit_lua_initiate_once(noit_module_t *self, noit_check_t *check,
noit_check_t *cause) {
return noit_lua_initiate_ex(self, check, cause, mtev_true);
}

/* This is the standard wrapper */
static int
noit_lua_module_initiate_check(noit_module_t *self, noit_check_t *check,
int once, noit_check_t *cause) {
INITIATE_CHECK(noit_lua_initiate, self, check, cause);
INITIATE_CHECK_EX(noit_lua_initiate, noit_lua_initiate_once,
self, check, cause);
return 0;
}

Expand Down
8 changes: 6 additions & 2 deletions src/noit_check_tools.h
Expand Up @@ -160,11 +160,11 @@ MTEV_HOOK_PROTO(check_postflight,
} \
} while(0)

#define INITIATE_CHECK(func, self, check, cause) do { \
#define INITIATE_CHECK_EX(func, oncefunc, self, check, cause) do { \
if(once) { \
if(MTEV_HOOK_CONTINUE == \
check_preflight_hook_invoke(self, check, cause)) \
func(self, check, cause); \
oncefunc(self, check, cause); \
check_postflight_hook_invoke(self, check, cause); \
} \
else if(!check->fire_event) { \
Expand All @@ -174,5 +174,9 @@ MTEV_HOOK_PROTO(check_postflight,
} \
} while(0)

#define INITIATE_CHECK(func, self, check, cause) do { \
INITIATE_CHECK_EX(func, func, self, check, cause); \
} while(0)

#endif

0 comments on commit 2054dcc

Please sign in to comment.