From: Alan T. DeKok Date: Wed, 19 Apr 2017 15:25:59 +0000 (-0400) Subject: return module_thread_instance_t, so we can access counters X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36a838dbdf6bc8b3d57e50b0bd68b00d252e8f07;p=thirdparty%2Ffreeradius-server.git return module_thread_instance_t, so we can access counters --- diff --git a/src/include/interpreter.h b/src/include/interpreter.h index 72e1d1fde38..ec1175c1290 100644 --- a/src/include/interpreter.h +++ b/src/include/interpreter.h @@ -162,7 +162,7 @@ typedef struct { */ typedef struct { unlang_module_call_t module; //!< Module call that returned #RLM_MODULE_YIELD. - void *thread; //!< data specific to the module. + module_thread_instance_t *thread; //!< thread-local data for this module fr_unlang_resume_t callback; //!< Function the yielding module indicated should //!< be called when the request could be resumed. fr_unlang_action_t action_callback; //!< Function the yielding module indicated should @@ -182,7 +182,7 @@ typedef struct { } unlang_xlat_inline_t; typedef struct { - void *thread; //!< Thread specific module instance. + module_thread_instance_t *thread; //!< thread-local data for this module } unlang_stack_entry_modcall_t; /** State of a foreach loop diff --git a/src/main/modules.c b/src/main/modules.c index 1ab2f67832b..4b082f11e7d 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -489,17 +489,12 @@ void *module_thread_instance_find(void *instance) { module_instance_t *inst = instance; rbtree_t *tree = module_thread_inst_tree; - module_thread_instance_t find, *found; - - if (!inst->module->thread_instantiate || !inst->module->thread_inst_size) return NULL; + module_thread_instance_t find; memset(&find, 0, sizeof(find)); find.inst = inst; - found = rbtree_finddata(tree, &find); - if (!found) return NULL; - - return found->data; + return rbtree_finddata(tree, &find); } /** Destructor for module_thread_instance_t diff --git a/src/main/unlang_interpret.c b/src/main/unlang_interpret.c index 78b5cee2754..5ffafbeee5b 100644 --- a/src/main/unlang_interpret.c +++ b/src/main/unlang_interpret.c @@ -703,6 +703,7 @@ static unlang_action_t unlang_module_call(REQUEST *request, unlang_stack_t *stac * Grab the thread/module specific data if any exists. */ frame->modcall.thread = module_thread_instance_find(sp->module_instance); + rad_assert(frame->modcall.thread != NULL); /* * For logging unresponsive children. @@ -710,7 +711,7 @@ static unlang_action_t unlang_module_call(REQUEST *request, unlang_stack_t *stac request->module = sp->module_instance->name; safe_lock(sp->module_instance); - request->rcode = sp->method(sp->module_instance->data, frame->modcall.thread, request); + request->rcode = sp->method(sp->module_instance->data, frame->modcall.thread->data, request); safe_unlock(sp->module_instance); request->module = NULL; @@ -850,7 +851,7 @@ static unlang_action_t unlang_resumption(REQUEST *request, unlang_stack_t *stack memcpy(&mutable, &mr->ctx, sizeof(mutable)); safe_lock(sp->module_instance); - *presult = mr->callback(request, mr->module.module_instance->data, mr->thread, mutable); + *presult = mr->callback(request, mr->module.module_instance->data, mr->thread->data, mutable); safe_unlock(sp->module_instance); RDEBUG2("%s (%s)", instruction->name ? instruction->name : "",