Remove empty lines in start of header files
[elinks.git] / src / main / object.h
blobe19c58003e458609d9c260bdf1a6e1fdc93b1bff
1 #ifndef EL__MAIN_OBJECT_H
2 #define EL__MAIN_OBJECT_H
4 #include "util/lists.h"
6 #if 0
7 #define DEBUG_REFCOUNT
8 #endif
10 struct object {
11 int refcount;
12 #ifdef CONFIG_DEBUG
13 unsigned char *name;
14 #endif
17 #define OBJECT_HEAD(type) \
18 LIST_HEAD(type); \
19 struct object object;
21 struct object_head {
22 OBJECT_HEAD(struct object *);
25 #ifdef DEBUG_REFCOUNT
26 #include "util/error.h"
27 #ifdef CONFIG_DEBUG
28 #define object_lock_debug(obj, info) \
29 DBG("object %s[%p] lock %s to %d", (obj)->object.name, obj, \
30 info, (obj)->object.refcount)
31 #else
32 #define object_lock_debug(obj, info) \
33 DBG("object %p lock %s to %d", obj, info, (obj)->object.refcount)
34 #endif /* CONFIG_DEBUG */
35 #else
36 #define object_lock_debug(obj, info)
37 #endif /* DEBUG_REFCOUNT */
39 #ifdef CONFIG_DEBUG
40 #include "util/error.h"
41 #define object_sanity_check(obj) \
42 do { \
43 assert(obj); \
44 assertm((obj)->object.refcount >= 0, \
45 "Object %s[%p] refcount underflow.", \
46 (obj)->object.name, obj); \
47 if_assert_failed (obj)->object.refcount = 0; \
48 } while (0)
50 #define object_set_name(obj, objname) \
51 do { (obj)->object.name = (objname); } while (0)
52 #define INIT_OBJECT(name) { 0, name }
53 #else
54 #define object_sanity_check(obj)
55 #define object_set_name(obj, name)
56 #define INIT_OBJECT(name) { 0 }
57 #endif /* CONFIG_DEBUG */
59 #define get_object_refcount(obj) ((obj)->object.refcount)
60 #define is_object_used(obj) (!!(obj)->object.refcount)
62 #define object_lock(obj) \
63 do { \
64 object_sanity_check(obj); \
65 (obj)->object.refcount++; \
66 object_lock_debug(obj, "incremented"); \
67 } while (0)
69 #define object_unlock(obj) \
70 do { \
71 (obj)->object.refcount--; \
72 object_lock_debug(obj, "decremented"); \
73 object_sanity_check(obj); \
74 } while (0)
76 /* Please keep this one. It serves for debugging. --Zas */
77 #define object_nolock(obj, name) \
78 do { \
79 object_set_name(obj, name); \
80 object_sanity_check(obj); \
81 object_lock_debug(obj, "initialized"); \
82 } while (0)
84 #endif