Tor  0.4.3.1-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-2020, 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
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",
81  .supported = true,
82  .level = 5,
83  .initialize = subsys_mainloop_initialize,
84  .shutdown = subsys_mainloop_shutdown,
85 
86  .state_format = &mainloop_state_fmt,
87  .set_state = mainloop_set_state,
88  .flush_state = mainloop_flush_state,
89 };
Header for mainloop_sys.c.
const char * name
Definition: subsys.h:42
static int mainloop_set_state(void *arg)
Definition: mainloop_sys.c:58
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
Declare a state structure for mainloop-relevant fields.
#define MAINLOOP_STATE_MAGIC
Definition: mainloop_sys.c:41
#define tor_assert(expr)
Definition: util_bug.h:102
void initialize_periodic_events(void)
Definition: mainloop.c:1526
Header file for mainloop.c.
Macros for generating a configuration struct from a list of its individual fields.
Types used to declare a subsystem.
Master header file for Tor-specific functionality.
Header for netstatus.c.
Types used to specify configurable options.
Declare configuration options for the crypto_ops module.
time_t approx_time(void)
Definition: approx_time.c:32
static config_format_t mainloop_state_fmt
Definition: mainloop_sys.c:46