blob: ba4ef35fba6354c04867889d61ec46321ae5e677 [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -05001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050023#ifndef WAYLAND_UTIL_H
24#define WAYLAND_UTIL_H
25
26/* GCC visibility */
27#if defined(__GNUC__) && __GNUC__ >= 4
28#define WL_EXPORT __attribute__ ((visibility("default")))
29#else
30#define WL_EXPORT
31#endif
32
33#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
34
35#define container_of(ptr, type, member) ({ \
36 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
37 (type *)( (char *)__mptr - offsetof(type,member) );})
38
39struct wl_hash {
40 struct wl_object **objects;
41 uint32_t count, alloc, id;
42};
43
44int wl_hash_insert(struct wl_hash *hash, struct wl_object *object);
45struct wl_object *wl_hash_lookup(struct wl_hash *hash, uint32_t id);
46void wl_hash_delete(struct wl_hash *hash, struct wl_object *object);
47
48struct wl_list {
49 struct wl_list *prev;
50 struct wl_list *next;
51};
52
53void wl_list_init(struct wl_list *list);
54void wl_list_insert(struct wl_list *list, struct wl_list *elm);
55void wl_list_remove(struct wl_list *elm);
56int wl_list_length(struct wl_list *list);
Kristian Høgsberg4a298902008-11-28 18:35:25 -050057int wl_list_empty(struct wl_list *list);
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050058
59
60#endif