25RCSID(
"$Id: 2ef38705fdabec2e013e515ea5048cd3a7a13210 $")
27#include <freeradius-devel/io/thread.h>
28#include <freeradius-devel/server/module_rlm.h>
29#include <freeradius-devel/server/virtual_servers.h>
30#include <freeradius-devel/server/main_config.h>
31#include <freeradius-devel/tls/base.h>
32#include <freeradius-devel/unlang/base.h>
33#include <freeradius-devel/util/syserror.h>
57 pthread_attr_init(&attr);
58 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
60 rcode = pthread_create(thread, &attr, func, arg);
63 pthread_attr_destroy(&attr);
66 pthread_attr_destroy(&attr);
81 unsigned int i,
count;
86 for (i = 0; i <
count; i++) {
128 pthread_sigmask(SIG_BLOCK, &sigset, NULL);
132 ctx = talloc_init(
"%s",
name);
134 ERROR(
"%s - Failed allocating memory",
name);
140 PERROR(
"%s - Failed creating event list",
name);
171 if (fr_openssl_thread_init(
main_config->openssl_async_pool_init,
172 main_config->openssl_async_pool_max) < 0)
return -1;
207 INFO(
"%s - Starting", thread->
name);
236 TALLOC_FREE(thread->
ctx);
#define fr_dlist_foreach(_list_head, _type, _iter)
Iterate over the contents of a list.
static void * fr_dlist_remove(fr_dlist_head_t *list_head, void *ptr)
Remove an item from the list.
static unsigned int fr_dlist_num_elements(fr_dlist_head_t const *head)
Return the number of elements in the dlist.
Head of a doubly linked list.
fr_event_list_t * fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_cb_t status, void *status_uctx)
Initialise a new event list.
void fr_event_loop_exit(fr_event_list_t *el, int code)
Signal an event loop exit with the specified code.
Stores all information relating to an event list.
main_config_t const * main_config
Main server configuration.
void modules_rlm_thread_detach(void)
Frees thread-specific data for all registered backend modules.
int modules_rlm_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el)
Allocates thread-specific data for all registered backend modules.
#define SEM_WAIT_INTR(_x)
Signals that can be sent to a request.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define talloc_strdup(_ctx, _str)
void fr_thread_start(fr_thread_t *thread, fr_sem_t *sem)
Signal the parent that we're done.
int fr_thread_wait_list(fr_sem_t *sem, fr_dlist_head_t *head)
Wait for multiple threads to signal readiness via a semaphore.
int fr_thread_create(pthread_t *thread, fr_thread_entry_t func, void *arg)
Create a joinable thread.
int fr_thread_setup(fr_thread_t *out, char const *name)
Common setup for child threads: block signals, allocate a talloc context, and create an event list.
int fr_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el)
Instantiate thread-specific data for modules, virtual servers, xlats, unlang, and TLS.
void fr_thread_detach(void)
Detach thread-specific data for modules, virtual servers, xlats.
void fr_thread_exit(fr_thread_t *thread, fr_thread_status_t status, fr_sem_t *sem)
Signal the parent that we're done.
fr_thread_status_t status
running, etc.
char const * name
of this thread
fr_event_list_t * el
our event list
fr_thread_status_t
Track the child thread status.
@ FR_THREAD_RUNNING
running, and in the running queue
@ FR_THREAD_INITIALIZING
initialized, but not running
@ FR_THREAD_FREE
child is free
TALLOC_CTX * ctx
our allocation ctx
void *(* fr_thread_entry_t)(void *)
static fr_event_list_t * el
int unlang_thread_instantiate(TALLOC_CTX *ctx)
Create thread-specific data structures for unlang.
void xlat_thread_detach(void)
Destroy any thread specific xlat instances.
int xlat_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el)
Create thread specific instance tree and create thread instances.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
static size_t char ** out
void virtual_servers_thread_detach(void)
Free thread-specific data for all process modules and listeners.
int virtual_servers_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el)
Perform thread instantiation for all process modules and listeners.