EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
em_init.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015-2024, Nokia Solutions and Networks
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef EM_INIT_H_
32#define EM_INIT_H_
33
34/**
35 * @file
36 * EM internal initialization
37 */
38
39#include <stdbool.h>
40
41#include <event_machine.h>
42
43#include "em_mem.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * Init values for the em_locm_t struct.
51 *
52 * Set only non-zero init values, other members initialized to '0'
53 * as per C standard when used to initialize a global struct.
54 *
55 * .core_id: 0 to EM_MAX_CORES-1 for EM_CORE_TYPE_WORKER or EM_CORE_TYPE_CONTROL
56 * -1 for EM_CORE_TYPE_EXTERNAL
57 * Undefined for threads/processes not initialized as EM-cores
58 * Set here to -2 to distinguish from EM_CORE_TYPE_EXTERNAL when not
59 * yet initialized via em_init_local()/em_init_core().
60 */
61#define EM_LOCM_INIT_VALUES {.core_id = -2, .local_queues.empty = 1 /* rest '0' */}
62
63/**
64 * Check whether the current thread/process has already completed EM core-local
65 * initialization.
66 *
67 * Works uniformly for both thread-per-core and process-per-core modes:
68 * - If locm->init_pid != getpid(), TLS is stale (first use or post-fork child)
69 * and the core is treated as not initialized.
70 * - Otherwise returns locm->is_core_local_inited, which is set true by
71 * em_init_local()/em_init_core() after successful core-local initialization.
72 *
73 * This is a pure check with no side effects. init_thr_mem() sets init_pid and
74 * em_init_local()/em_init_core() set is_core_local_inited.
75 */
76bool is_core_initialized(void);
77
78extern const em_locm_t locm_init_values; /* = EM_LOCM_INIT_VALUES */
79
80/**
81 * Set EM core local log function.
82 *
83 * Called by EM-core (= process, thread or bare metal core) when a
84 * different log function than EM internal log is needed.
85 *
86 */
88
89/**
90 * Set EM core local log function with va_list.
91 *
92 * Called by EM-core (= process, thread or bare metal core) when a
93 * different log function than EM internal log is needed.
94 *
95 */
97
98/**
99 * Initialize an external thread for the EM CLI.
100 *
101 * This function makes sure that EM shared memory has been setup properly before
102 * an EM external thread is created.
103 *
104 * Must be called once by non EM core which wants to access EM shared memory or
105 * use EM APIs.
106 *
107 * @return EM_OK if successful.
108 */
110
111em_status_t sync_api_init_local(void);
112
113em_status_t init_local(const em_conf_local_t *conf_local, em_escope_t escope);
114em_status_t init_extthr(const em_conf_local_t *conf_local, em_escope_t escope);
115
116void flush_scheduler_events(void);
117
118em_status_t term_core(em_escope_t escope);
119em_status_t term_extthr(em_escope_t escope);
120
121void cfgfile_opts_print(void);
122void conf_opts_print(void);
123void conf_local_opts_print(void);
124
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* EM_INIT_H_ */
void core_log_fn_set(em_log_func_t func)
Definition em_init.c:96
bool is_core_initialized(void)
Definition em_init.c:53
void core_vlog_fn_set(em_vlog_func_t func)
Definition em_init.c:103
em_status_t init_cli_thread(void)
Definition em_init.c:110
uint32_t em_escope_t
uint32_t em_status_t
int(* em_log_func_t)(em_log_level_t level, const char *fmt,...) __attribute__((format(printf
int(*) typedef int(* em_vlog_func_t)(em_log_level_t level, const char *fmt, va_list args)