EM-ODP  3.7.0
Event Machine on ODP
objpool.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 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 OBJPOOL_H_
32 #define OBJPOOL_H_
33 
34 /**
35  * @file
36  * Object-pool types & definitions
37  */
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
44 #include <list.h>
45 
46 #define OBJSUBPOOLS_MAX 8
47 
48 typedef struct {
49  list_node_t list_node;
50  uint32_t subpool_idx; /* 0 -> OBJSUBPOOLS_MAX - 1 */
51  uint32_t in_pool; /* true(1) / false(0) */
53 
54 typedef union {
55  uint8_t u8[ENV_CACHE_LINE_SIZE / 2];
56  struct {
57  env_spinlock_t lock;
58  list_node_t list_head;
59  };
60 } objsubpool_t;
61 
62 COMPILE_TIME_ASSERT(2 * sizeof(objsubpool_t) == ENV_CACHE_LINE_SIZE, OBJSUBPOOL_T_SIZE_ERROR);
63 
64 typedef struct {
65  objsubpool_t subpool[OBJSUBPOOLS_MAX];
66  uint32_t nbr_subpools;
67 } objpool_t;
68 
69 int objpool_init(objpool_t *const objpool, uint32_t nbr_subpools);
70 
71 void objpool_add(objpool_t *const objpool, uint32_t subpool_idx,
72  objpool_elem_t *const elem);
73 
75 objpool_rem(objpool_t *const objpool, uint32_t subpool_idx);
76 
77 int objpool_rem_elem(objpool_t *const objpool, objpool_elem_t *const elem);
78 
79 static inline int
80 objpool_in_pool(const objpool_elem_t *elem)
81 {
82  return elem->in_pool;
83 }
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif /* OBJPOOL_H_ */
ENV_CACHE_LINE_SIZE
#define ENV_CACHE_LINE_SIZE
Definition: environment.h:62
list_node_t
Definition: list.h:42
objpool_t
Definition: objpool.h:64
objpool_elem_t
Definition: objpool.h:48
environment.h
objsubpool_t
Definition: objpool.h:54