Motr  M0
pool.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2015-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_BE_POOL_H__
26 #define __MOTR_BE_POOL_H__
27 
28 #include "lib/misc.h" /* M0_HAS_TYPE */
29 #include "lib/mutex.h" /* m0_mutex */
30 #include "lib/tlist.h" /* m0_tl */
31 #include "lib/assert.h" /* M0_BASSERT */
32 #include "lib/types.h" /* uint64_t */
33 
34 struct m0_be_op;
35 struct be_pool_queue_item;
36 
45  unsigned bplc_q_size;
46 };
47 
57 struct m0_be_pool {
62  struct m0_tl bpl_free;
64  struct m0_tl bpl_used;
68  struct m0_tl bpl_q_free;
71 };
72 
79  uint64_t bpli_magic;
80  uint64_t bpli_pool_magic;
81 };
82 
88  const char *bpld_name;
94  uint64_t bpld_magic;
95 
96 };
97 
98 M0_INTERNAL int m0_be_pool_init(struct m0_be_pool *pool,
99  struct m0_be_pool_cfg *cfg);
100 M0_INTERNAL void m0_be_pool_fini(struct m0_be_pool *pool);
101 
103 M0_INTERNAL void m0_be_pool_add(const struct m0_be_pool_descr *d,
104  struct m0_be_pool *pool,
105  void *obj);
107 M0_INTERNAL void *m0_be_pool_del(const struct m0_be_pool_descr *d,
108  struct m0_be_pool *pool);
109 
113 M0_INTERNAL void m0_be_pool_get(const struct m0_be_pool_descr *d,
114  struct m0_be_pool *pool,
115  void **obj,
116  struct m0_be_op *op);
118 M0_INTERNAL void m0_be_pool_put(const struct m0_be_pool_descr *d,
119  struct m0_be_pool *pool,
120  void *obj);
121 
122 #define M0_BE_POOL_DESCR(hname, amb_type, pool_field, pool_magic_field, \
123  pool_magic) \
124 { \
125  .bpld_name = hname, \
126  .bpld_item_offset = offsetof(amb_type, pool_field), \
127  .bpld_magic_offset = offsetof(amb_type, pool_magic_field), \
128  .bpld_magic = pool_magic, \
129 }; \
130 M0_BASSERT(M0_HAS_TYPE(M0_FIELD_VALUE(amb_type, pool_field), \
131  struct m0_be_pool_item)); \
132 M0_BASSERT(M0_HAS_TYPE(M0_FIELD_VALUE(amb_type, pool_magic_field), \
133  uint64_t))
134 
135 #define M0_BE_POOL_DESCR_DEFINE(name, hname, scope, amb_type, pool_field, \
136  pool_magic_field, pool_magic) \
137 scope const struct m0_be_pool_descr name ## _pool_d = \
138  M0_BE_POOL_DESCR(hname, amb_type, pool_field, pool_magic_field, \
139  pool_magic)
140 
141 #define M0_BE_POOL_DEFINE(name, scope, amb_type) \
142  \
143 scope int name ## _be_pool_init(struct m0_be_pool *pool, \
144  struct m0_be_pool_cfg *cfg) \
145 { \
146  return m0_be_pool_init(pool, cfg); \
147 } \
148  \
149 scope void name ## _be_pool_fini(struct m0_be_pool *pool) \
150 { \
151  m0_be_pool_fini(pool); \
152 } \
153  \
154 scope void name ## _be_pool_add(struct m0_be_pool *pool, \
155  amb_type *obj) \
156 { \
157  m0_be_pool_add(&name ## _pool_d, pool, obj); \
158 } \
159  \
160 scope amb_type * name ## _be_pool_del(struct m0_be_pool *pool) \
161 { \
162  return (amb_type *)m0_be_pool_del(&name ## _pool_d, pool); \
163 } \
164  \
165 scope void name ## _be_pool_get(struct m0_be_pool *pool, \
166  amb_type **obj, \
167  struct m0_be_op *op) \
168 { \
169  m0_be_pool_get(&name ## _pool_d, pool, (void **)obj, op); \
170 } \
171  \
172 scope void name ## _be_pool_put(struct m0_be_pool *pool, \
173  amb_type *obj) \
174 { \
175  m0_be_pool_put(&name ## _pool_d, pool, obj); \
176 } \
177  \
178 struct __ ## name ## _terminate_me_with_a_semicolon { ; }
179 
181 #endif /* __MOTR_BE_POOL_H__ */
182 
183 /*
184  * Local variables:
185  * c-indentation-style: "K&R"
186  * c-basic-offset: 8
187  * tab-width: 8
188  * fill-column: 80
189  * scroll-step: 1
190  * End:
191  */
192 /*
193  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
194  */
M0_INTERNAL int m0_be_pool_init(struct m0_be_pool *pool, struct m0_be_pool_cfg *cfg)
Definition: pool.c:58
const char * bpld_name
Definition: pool.h:88
int bpld_magic_offset
Definition: pool.h:92
M0_INTERNAL void m0_be_pool_get(const struct m0_be_pool_descr *d, struct m0_be_pool *pool, void **obj, struct m0_be_op *op)
Definition: pool.c:226
static struct foo * obj
Definition: tlist.c:302
op
Definition: libdemo.c:64
struct m0_tl bpl_q_pending
Definition: pool.h:70
uint64_t bpli_pool_magic
Definition: pool.h:80
struct m0_mutex bpl_lock
Definition: pool.h:60
Definition: tlist.h:251
struct m0_tl bpl_q_free
Definition: pool.h:68
M0_INTERNAL void m0_be_pool_add(const struct m0_be_pool_descr *d, struct m0_be_pool *pool, void *obj)
Definition: pool.c:191
int bpld_item_offset
Definition: pool.h:90
unsigned bplc_q_size
Definition: pool.h:45
static struct m0_pool pool
Definition: iter_ut.c:58
uint64_t bpli_magic
Definition: pool.h:79
struct m0_tl bpl_used
Definition: pool.h:64
uint64_t bpld_magic
Definition: pool.h:94
struct m0_tlink bpli_link
Definition: pool.h:78
M0_INTERNAL void * m0_be_pool_del(const struct m0_be_pool_descr *d, struct m0_be_pool *pool)
Definition: pool.c:207
M0_INTERNAL void m0_be_pool_fini(struct m0_be_pool *pool)
Definition: pool.c:78
M0_INTERNAL void m0_be_pool_put(const struct m0_be_pool_descr *d, struct m0_be_pool *pool, void *obj)
Definition: pool.c:253
struct be_pool_queue_item * bpl_q_items
Definition: pool.h:66
Definition: op.h:74
Definition: mutex.h:47
struct m0_tl bpl_free
Definition: pool.h:62
struct m0_be_pool_cfg bpl_cfg
Definition: pool.h:58