2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 * @brief This file contains the interface to the pool class.
58 * This class allows two different two different priority tasks to
59 * insert and remove items from the free pool. The user of the pool
60 * is expected to evaluate the pool condition empty before a get
61 * operation and pool condition full before a put operation.
64 * - sci_pool_initialize()
74 #include <dev/isci/types.h>
77 * Private operation for the pool
79 #define SCI_POOL_INCREMENT(this_pool, index) \
80 (((index) + 1) == (this_pool).size ? 0 : (index) + 1)
83 * This creates a pool structure of pool_name. The members in the pool are
84 * of type with number of elements equal to size.
86 #define SCI_POOL_CREATE(pool_name, type, pool_size) \
92 type array[(pool_size) + 1]; \
97 * This macro evaluates the pool and returns TRUE if the pool is empty.
98 * If the pool is empty the user should not perform any get operation on
101 #define sci_pool_empty(this_pool) \
102 ((this_pool).get == (this_pool).put)
105 * This macro evaluates the pool and returns TRUE if the pool is full. If
106 * the pool is full the user should not perform any put operation.
108 #define sci_pool_full(this_pool) \
109 (SCI_POOL_INCREMENT(this_pool, (this_pool).put) == (this_pool).get)
112 * This macro returns the size of the pool created. The internal size
113 * of the pool is actually 1 larger then necessary in order to ensure
114 * get and put pointers can be written simultaneously by different
115 * users. As a result, this macro subtracts 1 from the internal size
117 #define sci_pool_size(this_pool) \
118 ((this_pool).size - 1)
121 * This macro indicates the number of elements currently contained in the
124 #define sci_pool_count(this_pool) \
126 sci_pool_empty((this_pool)) \
129 sci_pool_full((this_pool)) \
130 ? sci_pool_size((this_pool)) \
132 (this_pool).get > (this_pool).put \
133 ? ((this_pool).size - (this_pool).get + (this_pool).put) \
134 : ((this_pool).put - (this_pool).get) \
140 * This macro initializes the pool to an empty condition.
142 #define sci_pool_initialize(this_pool) \
144 (this_pool).size = (sizeof((this_pool).array) / sizeof((this_pool).array[0])); \
145 (this_pool).get = 0; \
146 (this_pool).put = 0; \
150 * This macro will get the next free element from the pool.
151 * This should only be called if the pool is not empty.
153 #define sci_pool_get(this_pool, my_value) \
155 (my_value) = (this_pool).array[(this_pool).get]; \
156 (this_pool).get = SCI_POOL_INCREMENT((this_pool), (this_pool).get); \
160 * This macro will put the value into the pool.
161 * This should only be called if the pool is not full.
163 #define sci_pool_put(this_pool, the_value) \
165 (this_pool).array[(this_pool).put] = (the_value); \
166 (this_pool).put = SCI_POOL_INCREMENT((this_pool), (this_pool).put); \
170 * This macro will search the pool and remove any elements in the pool
171 * matching the supplied value.
172 * @note This method can only be utilized on pools
174 #define sci_pool_erase(this_pool, type, the_value) \
178 U32 element_count = sci_pool_count((this_pool)); \
180 for (index = 0; index < element_count; index++) \
182 sci_pool_get((this_pool), tmp_value); \
183 if (tmp_value != (the_value)) \
184 sci_pool_put((this_pool), tmp_value); \
188 #endif // _SCI_POOL_H_