Tor  0.4.6.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-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
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 };
SUBSYS_DECLARE_LOCATION
#define SUBSYS_DECLARE_LOCATION()
Definition: subsys.h:211
approx_time
time_t approx_time(void)
Definition: approx_time.c:32
netstatus.h
Header for netstatus.c.
tor_assert
#define tor_assert(expr)
Definition: util_bug.h:102
initialize_periodic_events
void initialize_periodic_events(void)
Definition: mainloop.c:1522
mainloop_state_fmt
static config_format_t mainloop_state_fmt
Definition: mainloop_sys.c:46
mainloop_sys.h
Header for mainloop_sys.c.
confdecl.h
Macros for generating a configuration struct from a list of its individual fields.
config_format_t
Definition: conftypes.h:347
MAINLOOP_STATE_MAGIC
#define MAINLOOP_STATE_MAGIC
Definition: mainloop_sys.c:41
mainloop.h
Header file for mainloop.c.
subsys.h
Types used to declare a subsystem.
subsys_fns_t::name
const char * name
Definition: subsys.h:43
netstatus_flush_to_state
void netstatus_flush_to_state(mainloop_state_t *state, time_t now)
Definition: netstatus.c:119
config_format_t::size
size_t size
Definition: conftypes.h:348
netstatus_load_from_state
void netstatus_load_from_state(const mainloop_state_t *state, time_t now)
Definition: netstatus.c:134
mainloop_state.inc
Declare configuration options for the crypto_ops module.
mainloop_state_st.h
Declare a state structure for mainloop-relevant fields.
conftypes.h
Types used to specify configurable options.
mainloop_state_t
Definition: mainloop_state.inc:9
subsys_fns_t
Definition: subsys.h:38
or.h
Master header file for Tor-specific functionality.