summaryrefslogtreecommitdiff
path: root/regress/sys/net/rtable/srp_compat.h
blob: 3059ac0de03af51e1ae134552b333216e5555b79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

#ifndef _SRP_COMPAT_H_
#define _SRP_COMPAT_H_

#include <sys/srp.h>
#include <sys/queue.h>

/*
 * SRP glue.
 */

#define srp_follow(_sr, _s)		((_s)->ref)
#define srp_leave(_sr)			do { } while (0)
#define srp_swap(_srp, _v)		srp_swap_locked((_srp), (_v))
#define srp_update(_gc, _srp, _v)	srp_update_locked((_gc), (_srp), (_v))
#define srp_finalize(_v, _wchan)	((void)0)

#define srp_get_locked(_s)		((_s)->ref)

static inline void *
srp_enter(struct srp_ref *_sr, struct srp *_s)
{
	return (_s->ref);
}

static inline void *
srp_swap_locked(struct srp *srp, void *nv)
{
	void *ov;

	ov = srp->ref;
	srp->ref = nv;

	return (ov);
}

#define srp_update_locked(_gc, _s, _v) do {				\
	void *ov;							\
									\
	ov = srp_swap_locked(_s, _v);					\
									\
	if (ov != NULL)							\
		((_gc)->srp_gc_dtor)((_gc)->srp_gc_cookie, ov);		\
} while (0)

/*
 * SRPL glue.
 */

#define SRPL_INIT(_sl)			SLIST_INIT(_sl)
#define SRPL_HEAD(name, entry)		SLIST_HEAD(name, entry)
#define SRPL_ENTRY(type)		SLIST_ENTRY(type)

#define SRPL_FIRST(_sr, _sl)		SLIST_FIRST(_sl);
#define SRPL_NEXT(_sr, _e, _ENTRY)	SLIST_NEXT(_e, _ENTRY)
#define SRPL_FOLLOW(_sr, _e, _ENTRY)	SLIST_NEXT(_e, _ENTRY)
#define SRPL_LEAVE(_sr)			((void)_sr)

#define SRPL_FOREACH(_c, _srp, _sl, _ENTRY)				\
		SLIST_FOREACH(_c, _sl, _ENTRY)


#define SRPL_EMPTY_LOCKED(_sl)		SLIST_EMPTY(_sl)
#define SRPL_FIRST_LOCKED(_sl)		SLIST_FIRST(_sl)
#define SRPL_NEXT_LOCKED(_e, _ENTRY)	SLIST_NEXT(_e, _ENTRY)

#define SRPL_FOREACH_LOCKED(_c, _sl, _ENTRY)				\
		SLIST_FOREACH(_c, _sl, _ENTRY)

#define SRPL_FOREACH_SAFE_LOCKED(_c, _sl, _ENTRY, _tc)			\
		SLIST_FOREACH_SAFE(_c, _sl, _ENTRY, _tc)

#define SRPL_INSERT_HEAD_LOCKED(_rc, _sl, _e, _ENTRY)			\
	do {								\
		(_rc)->srpl_ref((_rc)->srpl_cookie, _e);		\
		SLIST_INSERT_HEAD(_sl, _e, _ENTRY);			\
	} while (0)

#define SRPL_INSERT_AFTER_LOCKED(_rc, _se, _e, _ENTRY)			\
	do {								\
		(_rc)->srpl_ref((_rc)->srpl_cookie, _e);		\
		SLIST_INSERT_AFTER(_se, _e, _ENTRY);			\
	} while (0)

#define SRPL_REMOVE_LOCKED(_rc, _sl, _e, _type, _ENTRY)			\
	do {								\
		SLIST_REMOVE(_sl, _e, _type, _ENTRY);			\
		((_rc)->srpl_gc.srp_gc_dtor)((_rc)->srpl_gc.srp_gc_cookie, _e);\
	} while (0)

#endif /* _SRP_COMPAT_H_ */