xref: /openbsd-src/regress/sys/net/rtable/srp_compat.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
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_enter(_sr, _s)		((_s)->ref)
13 #define srp_follow(_sr, _s)		((_s)->ref)
14 #define srp_leave(_sr)			do { } while (0)
15 #define srp_swap(_srp, _v)		srp_swap_locked((_srp), (_v))
16 #define srp_update(_gc, _srp, _v)	srp_update_locked((_gc), (_srp), (_v))
17 #define srp_finalize(_v, _wchan)	((void)0)
18 
19 #define srp_get_locked(_s)		((_s)->ref)
20 
21 static inline void *
22 srp_swap_locked(struct srp *srp, void *nv)
23 {
24 	void *ov;
25 
26 	ov = srp->ref;
27 	srp->ref = nv;
28 
29 	return (ov);
30 }
31 
32 #define srp_update_locked(_gc, _s, _v) do {				\
33 	void *ov;							\
34 									\
35 	ov = srp_swap_locked(_s, _v);					\
36 									\
37 	if (ov != NULL)							\
38 		((_gc)->srp_gc_dtor)((_gc)->srp_gc_cookie, ov);		\
39 } while (0)
40 
41 /*
42  * SRPL glue.
43  */
44 
45 #define SRPL_INIT(_sl)			SLIST_INIT(_sl)
46 #define SRPL_HEAD(name, entry)		SLIST_HEAD(name, entry)
47 #define SRPL_ENTRY(type)		SLIST_ENTRY(type)
48 
49 #define SRPL_ENTER(_sr, _sl)		SLIST_FIRST(_sl);
50 #define SRPL_NEXT(_sr, _e, _ENTRY)	SLIST_NEXT(_e, _ENTRY)
51 #define SRPL_LEAVE(_sr)			((void)_sr)
52 
53 #define SRPL_FOREACH(_c, _srp, _sl, _ENTRY)				\
54 		SLIST_FOREACH(_c, _sl, _ENTRY)
55 
56 #define SRPL_EMPTY_LOCKED(_sl)	SLIST_EMPTY(_sl)
57 #define SRPL_FOREACH_SAFE_LOCKED(_c, _sl, _ENTRY, _tc)			\
58 		SLIST_FOREACH_SAFE(_c, _sl, _ENTRY, _tc)
59 
60 #define SRPL_INSERT_HEAD_LOCKED(_rc, _sl, _e, _ENTRY)			\
61 	do {								\
62 		(_rc)->srpl_ref((_rc)->srpl_cookie, _e);		\
63 		SLIST_INSERT_HEAD(_sl, _e, _ENTRY);			\
64 	} while (0)
65 
66 #define SRPL_REMOVE_LOCKED(_rc, _sl, _e, _type, _ENTRY)			\
67 	do {								\
68 		SLIST_REMOVE(_sl, _e, _type, _ENTRY);			\
69 		((_rc)->srpl_gc.srp_gc_dtor)((_rc)->srpl_gc.srp_gc_cookie, _e);\
70 	} while (0)
71 
72 #endif /* _SRP_COMPAT_H_ */
73