return NULL;
}
- /*
- * Glue workers into the trigger code.
- */
- trigger_worker_request_add = fr_worker_request_add;
-
sc->config = config;
sc->el = el;
sc->log = logger;
#define WORKER_VERIFY
#endif
-static _Thread_local fr_worker_t *thread_local_worker;
-
#define CACHE_LINE_SIZE 64
static alignas(CACHE_LINE_SIZE) atomic_uint64_t request_number = 0;
fr_channel_responder_ack_close(worker->channel[i]);
}
- thread_local_worker = NULL;
talloc_free(worker);
}
fr_strerror_const("Failed initialising interpreter");
goto fail;
}
-
- thread_local_worker = worker;
+ unlang_interpret_set_thread_default(worker->intp);
return worker;
}
worker_run_request(worker, fr_time()); /* Event loop time can be too old, and trigger asserts */
}
-/** Asynchronously add a request_t to a worker thread
- *
- * When we don't know what the worker is...
- *
- * @param[in] request to add.
- * @param[in] process module method to call when the request is executed.
- * @param[in] uctx to pass to the process method.
- * @return
- * - 0 on success.
- * - -1 on failure.
- */
-int fr_worker_request_add(request_t *request, module_method_t process, void *uctx)
-{
- fr_worker_t *worker;
- fr_time_t now;
-
- worker = thread_local_worker;
- if (unlikely(!worker)) {
- fr_strerror_const("No worker has been defined");
- return -1;
- }
-
- now = fr_time();
-
- worker_request_init(worker, request, now);
- worker_request_name_number(request);
-
- fr_assert(request_is_internal(request));
- request->async->process = process;
- request->async->process_inst = uctx;
-
- worker_request_time_tracking_start(worker, request, now);
-
- return 0;
-}
-
/** Print debug information about the worker structure
*
* @param[in] worker the worker
#include <freeradius-devel/server/module.h>
-int fr_worker_request_add(request_t *request, module_method_t process, void *uctx) CC_HINT(nonnull(1,2));
-
int fr_worker_subrequest_add(request_t *request) CC_HINT(nonnull);
#ifdef __cplusplus
#include <freeradius-devel/unlang/interpret.h>
#include <freeradius-devel/util/debug.h>
-/*
- * Public "thunk" API so that the various binaries can link to
- * libfreeradius-server.a, and don't need to be linked to libfreeradius-io.a
- */
-fr_trigger_worker_t trigger_worker_request_add = NULL;
-
/** Whether triggers are enabled globally
*
*/
* We don't register the trigger xlat here, as we may inadvertently initialise
* the xlat code, which is annoying when this is called from a utility.
*
- * @param cs to use as global trigger section.
+ * @param[in] cs to use as global trigger section.
* @return
* - 0 on success.
* - -1 on failure.
trigger_mutex = talloc(talloc_null_ctx(), pthread_mutex_t);
pthread_mutex_init(trigger_mutex, 0);
talloc_set_destructor(trigger_mutex, _mutex_free);
-
triggers_init = true;
return 0;
return -1;
}
+ /*
+ * Always run triggers in the default interpreter
+ */
+ unlang_interpret_set(child, unlang_interpret_get_thread_default());
+
if (unlang_subrequest_child_push_and_detach(child) < 0) goto error;
if (unlang_interpret_push_function(child, trigger_run, trigger_resume,
void trigger_args_afrom_server(TALLOC_CTX *ctx, fr_pair_list_t *list, char const *server, uint16_t port);
typedef int (*fr_trigger_worker_t)(request_t *request, module_method_t process, void *ctx);
-extern fr_trigger_worker_t trigger_worker_request_add;
#ifdef __cplusplus
}
#include "parallel_priv.h"
#include "unlang_priv.h"
+/** The default interpreter instance for this thread
+ */
+static _Thread_local unlang_interpret_t *intp_thread_default;
+
static fr_table_num_ordered_t const unlang_action_table[] = {
{ L("unwind"), UNLANG_ACTION_UNWIND },
{ L("calculate-result"), UNLANG_ACTION_CALCULATE_RESULT },
return stack->intp;
}
+/** Set the default interpreter for this thread
+ *
+
+ */
+void unlang_interpret_set_thread_default(unlang_interpret_t *intp)
+{
+ intp_thread_default = talloc_get_type_abort(intp, unlang_interpret_t);
+}
+
+/** Get the default interpreter for this thread
+ *
+ * This allows detached requests to be executed asynchronously
+ */
+unlang_interpret_t *unlang_interpret_get_thread_default(void)
+{
+ return talloc_get_type_abort(intp_thread_default, unlang_interpret_t);
+}
+
void unlang_interpret_init_global(void)
{
xlat_t *xlat;
unlang_interpret_t *unlang_interpret_get(request_t *request);
+void unlang_interpret_set_thread_default(unlang_interpret_t *intp);
+
+unlang_interpret_t *unlang_interpret_get_thread_default(void);
+
rlm_rcode_t unlang_interpret(request_t *request) CC_HINT(hot);
rlm_rcode_t unlang_interpret_synchronous(request_t *request);
unlang_frame_state_subrequest_t *state;
unlang_stack_frame_t *frame;
- /*
- * Run in the same interpreter as the parent
- */
- unlang_interpret_set(child, unlang_interpret_get(child->parent));
-
/*
* Push a new subrequest frame onto the stack
*
int unlang_subrequest_child_push_and_detach(request_t *child)
{
- /*
- * Run in the same interpreter as the parent
- */
- unlang_interpret_set(child, unlang_interpret_get(child->parent));
-
/*
* Ensures the child is setup correctly and adds
* it into the runnable queue of whatever owns