Tor  0.4.7.0-alpha-dev
mainloop_sys.c
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * @file mainloop_sys.c
9  * @brief Declare the "mainloop" subsystem.
10  **/
11 
12 #include "core/or/or.h"
14 #include "core/mainloop/mainloop.h"
17 #include "lib/conf/conftypes.h"
18 #include "lib/conf/confdecl.h"
19 
20 #include "lib/subsys/subsys.h"
21 
22 static int
23 subsys_mainloop_initialize(void)
24 {
26  return 0;
27 }
28 
29 static void
30 subsys_mainloop_shutdown(void)
31 {
32  tor_mainloop_free_all();
33 }
34 
35 /** Declare a list of state variables for mainloop state. */
36 #define CONF_CONTEXT TABLE
38 #undef CONF_CONTEXT
39 
40 /** Magic number for mainloop state objects */
41 #define MAINLOOP_STATE_MAGIC 0x59455449
42 
43 /**
44  * Format object for mainloop state.
45  **/
47  .size = sizeof(mainloop_state_t),
48  .magic = { "mainloop_state",
50  offsetof(mainloop_state_t, magic)
51  },
52  .vars = mainloop_state_t_vars,
53 };
54 
55 /**
56  */
57 static int
58 mainloop_set_state(void *arg)
59 {
60  const mainloop_state_t *state = arg;
61  tor_assert(state->magic == MAINLOOP_STATE_MAGIC);
62 
64 
65  return 0;
66 }
67 
68 static int
69 mainloop_flush_state(void *arg)
70 {
71  mainloop_state_t *state = arg;
72  tor_assert(state->magic == MAINLOOP_STATE_MAGIC);
73 
75 
76  return 0;
77 }
78 
79 const struct subsys_fns_t sys_mainloop = {
80  .name = "mainloop",
82  .supported = true,
83  .level = 5,
84  .initialize = subsys_mainloop_initialize,
85  .shutdown = subsys_mainloop_shutdown,
86 
87  .state_format = &mainloop_state_fmt,
88  .set_state = mainloop_set_state,
89  .flush_state = mainloop_flush_state,
90 };
time_t approx_time(void)
Definition: approx_time.c:32
Macros for generating a configuration struct from a list of its individual fields.
Types used to specify configurable options.
void initialize_periodic_events(void)
Definition: mainloop.c:1519
Header file for mainloop.c.
Declare configuration options for the crypto_ops module.
Declare a state structure for mainloop-relevant fields.
#define MAINLOOP_STATE_MAGIC
Definition: mainloop_sys.c:41
static config_format_t mainloop_state_fmt
Definition: mainloop_sys.c:46
Header for mainloop_sys.c.
void netstatus_load_from_state(const mainloop_state_t *state, time_t now)
Definition: netstatus.c:134
void netstatus_flush_to_state(mainloop_state_t *state, time_t now)
Definition: netstatus.c:119
Header for netstatus.c.
Master header file for Tor-specific functionality.
const char * name
Definition: subsys.h:43
Types used to declare a subsystem.
#define SUBSYS_DECLARE_LOCATION()
Definition: subsys.h:211
#define tor_assert(expr)
Definition: util_bug.h:102