Bump version to 0.3.5next
[archipelago] / xseg / xtypes / xpool.h
1 /*
2  * Copyright 2012 GRNET S.A. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above
9  *      copyright notice, this list of conditions and the following
10  *      disclaimer.
11  *   2. Redistributions in binary form must reproduce the above
12  *      copyright notice, this list of conditions and the following
13  *      disclaimer in the documentation and/or other materials
14  *      provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * The views and conclusions contained in the software and
30  * documentation are those of the authors and should not be
31  * interpreted as representing official policies, either expressed
32  * or implied, of GRNET S.A.
33  */
34
35 #ifndef XPOOL_H
36 #define XPOOL_H
37
38 #include <sys/util.h>
39 #include <xtypes/xlock.h>
40
41 typedef uint64_t xpool_index;
42 typedef uint64_t xpool_data;
43 #define NoIndex ((xpool_index) -1)
44
45
46 struct xpool_node {
47         xpool_data data;
48         //XPTR_TYPE(struct xpool_node) next;
49         //XPTR_TYPE(struct xpool_node) prev;
50         xpool_index next;
51         xpool_index prev;
52 };
53
54 struct xpool {
55         struct xlock lock;
56         //XPTR_TYPE(struct xpool_node) list;
57         //XPTR_TYPE(struct xpool_node) free;
58         xpool_index list;
59         xpool_index free;
60         uint64_t size;
61         XPTR_TYPE(struct xpool_node) mem;
62 };
63
64 void xpool_init(struct xpool *xp, uint64_t size, struct xpool_node* mem);
65 void xpool_clear(struct xpool *xp, uint32_t who);
66 xpool_index xpool_add(struct xpool *xp, xpool_data data, uint32_t who);
67 xpool_index xpool_remove(struct xpool *xp, xpool_index idx, xpool_data *data, uint32_t who);
68 xpool_index xpool_peek(struct xpool *xp, xpool_data *data, uint32_t who);
69 xpool_index xpool_peek_idx(struct xpool *xp, xpool_index idx, xpool_data *data, uint32_t who);
70 xpool_index xpool_peek_and_fwd(struct xpool *xp, xpool_data *data, uint32_t who);
71 xpool_index xpool_set_idx(struct xpool *xp, xpool_index idx, xpool_data data, uint32_t who);
72
73 void __xpool_clear(struct xpool *xp);
74 xpool_index __xpool_add(struct xpool *xp, xpool_data data);
75 xpool_index __xpool_remove(struct xpool *xp, xpool_index idx, xpool_data *data);
76 xpool_index __xpool_peek(struct xpool *xp, xpool_data *data);
77 xpool_index __xpool_peek_idx(struct xpool *xp, xpool_index idx, xpool_data *data);
78 xpool_index __xpool_peek_and_fwd(struct xpool *xp, xpool_data *data);
79 xpool_index __xpool_set_idx(struct xpool *xp, xpool_index idx, xpool_data data);
80
81 #endif /* XPOOL_H */