The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
coord.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: f93afd986e308bf1c181410b61234ea58b8be6ec $
20 *
21 * @file io/coord.h
22 * @brief Coordination thread management
23 *
24 * @copyright 2026 Network RADIUS SAS (legal@networkradius.com)
25 */
26RCSIDH(coord_h, "$Id: f93afd986e308bf1c181410b61234ea58b8be6ec $")
27
28#include <freeradius-devel/io/control.h>
29#include <freeradius-devel/io/message.h>
30#include <freeradius-devel/server/cf_util.h>
31#include <freeradius-devel/util/dbuff.h>
32#include <freeradius-devel/util/semaphore.h>
33
35
36typedef struct fr_coord_s fr_coord_t;
39
40typedef void (*fr_coord_cb_t)(fr_coord_t *coord, uint32_t worker_id, fr_dbuff_t *dbuff, fr_time_t now, void *plugin_data, void *uctx);
41typedef void (*fr_coord_worker_cb_t)(fr_coord_worker_t *cw, fr_dbuff_t *dbuff, fr_time_t now, void *uctx);
42typedef fr_coord_cb_inst_t *(*fr_coord_cb_inst_create_t)(TALLOC_CTX *ctx, fr_coord_t *coord, fr_event_list_t *el, bool single_thread, void *uctx);
43
50
51typedef struct {
52 char const *name;
54 void *uctx;
56
57#define FR_COORD_CALLBACK_TERMINATOR { .callback = NULL }
58
59typedef struct {
60 char const *name; //!< Name for this coordinator.
61 fr_coord_cb_reg_t *coord_cb; //!< Callbacks for worker -> coordinator messages.
62 fr_coord_worker_cb_reg_t *worker_cb; //!< Callbacks for coordinator -> worker messages.
63 size_t worker_send_size; //!< Initial ring buffer size for worker -> coordinator
64 ///< data. Defaults to 4096 if not set.
65 size_t coord_send_size; //!< Initial ring buffer size for coordinator -> worker
66 ///< data. Defaults to 4096 of not set.
68
69typedef struct {
71 void *uctx;
73
78
79fr_coord_reg_t *fr_coord_register(TALLOC_CTX *ctx, fr_coord_reg_ctx_t *reg_ctx);
80
81void fr_coord_deregister(fr_coord_reg_t *coord_reg);
82
84
85int fr_coords_create(TALLOC_CTX *ctx, fr_event_list_t *el);
86
87void fr_coords_destroy(void);
88
90int fr_coord_detach(fr_coord_worker_t *cw, bool exiting);
91
93
95
97
99
#define RCSIDH(h, id)
Definition build.h:489
static size_t num_workers
A coordinator registration.
Definition coord.c:83
A coordinator which receives messages from workers.
Definition coord.c:47
The worker end of worker <-> coordinator communication.
Definition coord.c:71
char const * name
Definition coord.h:45
int fr_coords_create(TALLOC_CTX *ctx, fr_event_list_t *el)
Start coordinators in single threaded mode.
Definition coord.c:558
fr_coord_reg_t * fr_coord_register(TALLOC_CTX *ctx, fr_coord_reg_ctx_t *reg_ctx)
Register a coordinator.
Definition coord.c:135
fr_coord_worker_t * fr_coord_attach(TALLOC_CTX *ctx, fr_event_list_t *el, fr_coord_reg_t *coord_reg)
Attach a worker to a coordinator.
Definition coord.c:628
fr_coord_cb_t callback
Definition coord.h:46
int fr_coord_to_worker_send(fr_coord_t *coord, uint32_t worker_id, uint32_t cb_id, fr_dbuff_t *dbuff)
Send generic data from a coordinator to a worker.
Definition coord.c:691
fr_coord_cb_reg_t * coord_cb
Callbacks for worker -> coordinator messages.
Definition coord.h:61
void fr_coord_deregister(fr_coord_reg_t *coord_reg)
De-register a coordinator.
Definition coord.c:167
void fr_coords_destroy(void)
Clean up coordinators in single threaded mode.
Definition coord.c:540
int fr_worker_to_coord_send(fr_coord_worker_t *cw, uint32_t cb_id, fr_dbuff_t *dbuff)
Send data from a worker to a coordinator.
Definition coord.c:746
void(* fr_coord_worker_cb_t)(fr_coord_worker_t *cw, fr_dbuff_t *dbuff, fr_time_t now, void *uctx)
Definition coord.h:41
int fr_coord_post_event_insert(fr_event_list_t *el)
Insert instance specific post-event callbacks.
Definition coord.c:796
int fr_coord_pre_event_insert(fr_event_list_t *el)
Insert instance specific pre-event callbacks.
Definition coord.c:771
char const * name
Definition coord.h:52
void * uctx
Definition coord.h:48
char const * name
Name for this coordinator.
Definition coord.h:60
fr_coord_worker_cb_t callback
Definition coord.h:53
size_t coord_send_size
Initial ring buffer size for coordinator -> worker data.
Definition coord.h:65
fr_coord_t * coord
Definition coord.h:70
void(* fr_coord_cb_t)(fr_coord_t *coord, uint32_t worker_id, fr_dbuff_t *dbuff, fr_time_t now, void *plugin_data, void *uctx)
Definition coord.h:40
fr_coord_worker_cb_reg_t * worker_cb
Callbacks for coordinator -> worker messages.
Definition coord.h:62
int fr_coord_start(uint32_t num_workers, fr_sem_t *sem)
Start all registered coordinator threads in multi-threaded mode.
Definition coord.c:490
fr_coord_worker_t * cw
Definition coord.h:75
size_t worker_send_size
Initial ring buffer size for worker -> coordinator data.
Definition coord.h:63
int fr_coord_to_worker_broadcast(fr_coord_t *coord, uint32_t cb_id, fr_dbuff_t *dbuff)
Broadcast data from a coordinator to all workers.
Definition coord.c:724
int fr_coord_detach(fr_coord_worker_t *cw, bool exiting)
Signal a coordinator that a worker wants to detach.
Definition coord.c:589
fr_coord_cb_inst_create_t inst_create
Definition coord.h:47
fr_coord_cb_inst_t *(* fr_coord_cb_inst_create_t)(TALLOC_CTX *ctx, fr_coord_t *coord, fr_event_list_t *el, bool single_thread, void *uctx)
Definition coord.h:42
Stores all information relating to an event list.
Definition event.c:377
unsigned int uint32_t
static _Thread_local int worker_id
Internal ID of the current worker thread.
Definition schedule.c:103
sem_t fr_sem_t
Definition semaphore.h:53
"server local" time.
Definition time.h:69
static fr_event_list_t * el