1
2 #ifndef _SRP_COMPAT_H_
3 #define _SRP_COMPAT_H_
4
5 #include <sys/srp.h>
6 #include <sys/queue.h>
7
8 /*
9 * SRP glue.
10 */
11
12 #define srp_follow(_sr, _s) ((_s)->ref)
13 #define srp_leave(_sr) do { } while (0)
14 #define srp_swap(_srp, _v) srp_swap_locked((_srp), (_v))
15 #define srp_update(_gc, _srp, _v) srp_update_locked((_gc), (_srp), (_v))
16 #define srp_finalize(_v, _wchan) ((void)0)
17
18 #define srp_get_locked(_s) ((_s)->ref)
19
20 static inline void *
srp_enter(struct srp_ref * _sr,struct srp * _s)21 srp_enter(struct srp_ref *_sr, struct srp *_s)
22 {
23 return (_s->ref);
24 }
25
26 static inline void *
srp_swap_locked(struct srp * srp,void * nv)27 srp_swap_locked(struct srp *srp, void *nv)
28 {
29 void *ov;
30
31 ov = srp->ref;
32 srp->ref = nv;
33
34 return (ov);
35 }
36
37 #define srp_update_locked(_gc, _s, _v) do { \
38 void *ov; \
39 \
40 ov = srp_swap_locked(_s, _v); \
41 \
42 if (ov != NULL) \
43 ((_gc)->srp_gc_dtor)((_gc)->srp_gc_cookie, ov); \
44 } while (0)
45
46 /*
47 * SRPL glue.
48 */
49
50 #define SRPL_INIT(_sl) SLIST_INIT(_sl)
51 #undef SRPL_HEAD
52 #define SRPL_HEAD(name, entry) SLIST_HEAD(name, entry)
53 #undef SRPL_ENTRY
54 #define SRPL_ENTRY(type) SLIST_ENTRY(type)
55
56 #define SRPL_FIRST(_sr, _sl) SLIST_FIRST(_sl);
57 #define SRPL_NEXT(_sr, _e, _ENTRY) SLIST_NEXT(_e, _ENTRY)
58 #define SRPL_FOLLOW(_sr, _e, _ENTRY) SLIST_NEXT(_e, _ENTRY)
59 #define SRPL_LEAVE(_sr) ((void)_sr)
60
61 #define SRPL_FOREACH(_c, _srp, _sl, _ENTRY) \
62 SLIST_FOREACH(_c, _sl, _ENTRY)
63
64
65 #define SRPL_EMPTY_LOCKED(_sl) SLIST_EMPTY(_sl)
66 #define SRPL_FIRST_LOCKED(_sl) SLIST_FIRST(_sl)
67 #define SRPL_NEXT_LOCKED(_e, _ENTRY) SLIST_NEXT(_e, _ENTRY)
68
69 #define SRPL_FOREACH_LOCKED(_c, _sl, _ENTRY) \
70 SLIST_FOREACH(_c, _sl, _ENTRY)
71
72 #define SRPL_FOREACH_SAFE_LOCKED(_c, _sl, _ENTRY, _tc) \
73 SLIST_FOREACH_SAFE(_c, _sl, _ENTRY, _tc)
74
75 #define SRPL_INSERT_HEAD_LOCKED(_rc, _sl, _e, _ENTRY) \
76 do { \
77 (_rc)->srpl_ref((_rc)->srpl_cookie, _e); \
78 SLIST_INSERT_HEAD(_sl, _e, _ENTRY); \
79 } while (0)
80
81 #define SRPL_INSERT_AFTER_LOCKED(_rc, _se, _e, _ENTRY) \
82 do { \
83 (_rc)->srpl_ref((_rc)->srpl_cookie, _e); \
84 SLIST_INSERT_AFTER(_se, _e, _ENTRY); \
85 } while (0)
86
87 #define SRPL_REMOVE_LOCKED(_rc, _sl, _e, _type, _ENTRY) \
88 do { \
89 SLIST_REMOVE(_sl, _e, _type, _ENTRY); \
90 ((_rc)->srpl_gc.srp_gc_dtor)((_rc)->srpl_gc.srp_gc_cookie, _e);\
91 } while (0)
92
93 #endif /* _SRP_COMPAT_H_ */
94