The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
schedule.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: 9c91134ac01cdb2464aff87433a43c5d449e122e $
20  *
21  * @file io/schedule.h
22  * @brief Scheduler communication.
23  *
24  * @copyright 2016 Alan DeKok (aland@freeradius.org)
25  */
26 RCSIDH(schedule_h, "$Id: 9c91134ac01cdb2464aff87433a43c5d449e122e $")
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef struct fr_schedule_s fr_schedule_t;
33 
34 #ifdef __cplusplus
35 }
36 #endif
37 
38 #include <freeradius-devel/io/channel.h>
39 #include <freeradius-devel/io/network.h>
40 #include <freeradius-devel/io/worker.h>
41 #include <freeradius-devel/util/log.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 /** Setup a new thread
47  *
48  * @param[in] ctx to allocate any thread specific memory in.
49  * @param[in] el Event list used by the thread.
50  * @param[in] uctx User data passed to callback.
51  * @return
52  * - 0 on success.
53  * - -1 on failure.
54  */
55 typedef int (*fr_schedule_thread_instantiate_t)(TALLOC_CTX *ctx, fr_event_list_t *el, void *uctx);
56 
57 /** Explicitly free resources allocated by #fr_schedule_thread_instantiate_t
58  *
59  * @param[in] uctx User data passed to callback.
60  */
61 typedef void (*fr_schedule_thread_detach_t)(void *uctx);
62 
63 typedef struct {
64  uint32_t max_networks; //!< number of network threads
65  uint32_t max_workers; //!< number of network threads
66 
67  fr_worker_config_t worker; //!< configuration for each worker
68  fr_network_config_t network; //!< configuration for each network;
69 
70  fr_time_delta_t stats_interval; //!< print channel statistics
72 
73 int fr_schedule_worker_id(void);
74 
75 int fr_schedule_pthread_create(pthread_t *thread, void *(*func)(void *), void *arg);
77  fr_schedule_thread_instantiate_t worker_thread_instantiate,
78  fr_schedule_thread_detach_t worked_thread_detach,
79  fr_schedule_config_t *config) CC_HINT(nonnull(3));
80 /* schedulers are async, so there's no fr_schedule_run() */
82 
85 #ifdef __cplusplus
86 }
87 #endif
#define RCSIDH(h, id)
Definition: build.h:445
Stores all information relating to an event list.
Definition: event.c:411
fr_log_lvl_t
Definition: log.h:67
unsigned int uint32_t
Definition: merged_model.c:33
static const conf_parser_t config[]
Definition: base.c:188
The scheduler.
Definition: schedule.c:125
fr_network_config_t network
configuration for each network;
Definition: schedule.h:68
uint32_t max_workers
number of network threads
Definition: schedule.h:65
int(* fr_schedule_thread_instantiate_t)(TALLOC_CTX *ctx, fr_event_list_t *el, void *uctx)
Setup a new thread.
Definition: schedule.h:55
void(* fr_schedule_thread_detach_t)(void *uctx)
Explicitly free resources allocated by fr_schedule_thread_instantiate_t.
Definition: schedule.h:61
int fr_schedule_worker_id(void)
Return the worker id for the current thread.
Definition: schedule.c:157
int fr_schedule_pthread_create(pthread_t *thread, void *(*func)(void *), void *arg)
Creates a new thread using our standard set of options.
Definition: schedule.c:371
fr_schedule_t * fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_log_t *log, fr_log_lvl_t lvl, fr_schedule_thread_instantiate_t worker_thread_instantiate, fr_schedule_thread_detach_t worked_thread_detach, fr_schedule_config_t *config))
Create a scheduler and spawn the child threads.
Definition: schedule.c:409
fr_network_t * fr_schedule_directory_add(fr_schedule_t *sc, fr_listen_t *li)
Add a directory NOTE_EXTEND to a scheduler.
Definition: schedule.c:855
fr_worker_config_t worker
configuration for each worker
Definition: schedule.h:67
fr_time_delta_t stats_interval
print channel statistics
Definition: schedule.h:70
fr_network_t * fr_schedule_listen_add(fr_schedule_t *sc, fr_listen_t *li)
Add a fr_listen_t to a scheduler.
Definition: schedule.c:823
uint32_t max_networks
number of network threads
Definition: schedule.h:64
int fr_schedule_destroy(fr_schedule_t **sc)
Destroy a scheduler, and tell its child threads to exit.
Definition: schedule.c:703
static const uchar sc[16]
Definition: smbdes.c:115
Definition: log.h:96
A time delta, a difference in time measured in nanoseconds.
Definition: time.h:80
static fr_event_list_t * el
int nonnull(2, 5))