EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
em_pool_inline.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026, 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_POOL_INLINE_H_
32#define EM_POOL_INLINE_H_
33
34/**
35 * @file
36 * EM internal event pool inlined functions
37 */
38
39#include <stdint.h>
40
41#include <odp_api.h>
42
43#include <event_machine.h>
44
45#include "em_mem.h"
46#include "em_pool_types.h"
47#include "misc/objpool.h"
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/** Convert pool handle to pool index */
54static inline int
55pool_hdl2idx(em_pool_t pool)
56{
57 return (int)(uintptr_t)pool - 1;
58}
59
60/** Convert pool index to pool handle */
61static inline em_pool_t
62pool_idx2hdl(int pool_idx)
63{
64 return (em_pool_t)(uintptr_t)(pool_idx + 1);
65}
66
67/** Returns pool element associated with pool handle */
68static inline mpool_elem_t *
69pool_elem_get(em_pool_t pool)
70{
71 const int pool_idx = pool_hdl2idx(pool);
72 mpool_elem_t *mpool_elem;
73
74 if (unlikely((unsigned int)pool_idx > EM_CONFIG_POOLS - 1))
75 return NULL;
76
77 mpool_elem = &em_shm->mpool_tbl.pool[pool_idx];
78
79 return mpool_elem;
80}
81
82static inline int
83pool_allocated(const mpool_elem_t *const mpool_elem)
84{
85 return !objpool_in_pool(&mpool_elem->objpool_elem);
86}
87
88static inline int
89pool_find_subpool(const mpool_elem_t *const pool_elem, uint32_t size)
90{
91 int subpool;
92
93 /* Find the optimal subpool to allocate the event from */
94 for (subpool = 0; subpool < pool_elem->num_subpools &&
95 size > pool_elem->size[subpool]; subpool++)
96 ;
97
98 if (unlikely(subpool >= pool_elem->num_subpools))
99 return -1;
100
101 return subpool;
102}
103
104/**
105 * Get the EM event-pool that an odp-pool belongs to.
106 *
107 * An EM event-pool consists of up to EM_MAX_SUBPOOLS subpools (that are
108 * odp-pools) - a table (em_shm->mpool_tbl.pool_subpool_odp2em[]) contains the
109 * mapping and is populated during em_pool_create() calls.
110 */
111static inline em_pool_t
112pool_odp2em(odp_pool_t odp_pool)
113{
114 /*
115 * 'idx' is in the range: 0 to odp_pool_max_index(), which is smaller
116 * than the length of the em_shm->mpool_tbl.pool_subpool_odp2em[] array
117 * (verified at startup in pool_init()).
118 */
119 int idx = odp_pool_index(odp_pool);
120
121 if (unlikely(idx < 0))
122 return EM_POOL_UNDEF;
123
124 return (em_pool_t)(uintptr_t)em_shm->mpool_tbl.pool_subpool_odp2em[idx].pool;
125}
126
127/**
128 * Get the EM event-pool and subpool that an odp-pool belongs to.
129 *
130 * An EM event-pool consists of up to EM_MAX_SUBPOOLS subpools (that are
131 * odp-pools) - a table (em_shm->mpool_tbl.pool_subpool_odp2em[]) contains the
132 * mapping and is populated during em_pool_create() calls.
133 */
134static inline pool_subpool_t
135pool_subpool_odp2em(odp_pool_t odp_pool)
136{
137 /*
138 * 'idx' is in the range: 0 to odp_pool_max_index(), which is smaller
139 * than the length of the em_shm->mpool_tbl.pool_subpool_odp2em[] array
140 * (verified at startup in pool_init()).
141 */
142 int idx = odp_pool_index(odp_pool);
143
144 if (unlikely(idx < 0))
145 return pool_subpool_undef; /* .pool=EM_POOL_UNDEF, .subpool=0 */
146
147 return em_shm->mpool_tbl.pool_subpool_odp2em[idx];
148}
149
150#ifdef __cplusplus
151}
152#endif
153
154#endif /* EM_POOL_INLINE_H_ */
em_shm_t * em_shm
#define EM_CONFIG_POOLS
#define EM_POOL_UNDEF
objpool_elem_t objpool_elem
uint16_t size