srp_compat.h revision 1.4
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 21static inline void * 22srp_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_FIRST(_sr, _sl) SLIST_FIRST(_sl); 50#define SRPL_NEXT(_sr, _e, _ENTRY) SLIST_NEXT(_e, _ENTRY) 51#define SRPL_FOLLOW(_sr, _e, _ENTRY) SLIST_NEXT(_e, _ENTRY) 52#define SRPL_LEAVE(_sr) ((void)_sr) 53 54#define SRPL_FOREACH(_c, _srp, _sl, _ENTRY) \ 55 SLIST_FOREACH(_c, _sl, _ENTRY) 56 57#define SRPL_EMPTY_LOCKED(_sl) SLIST_EMPTY(_sl) 58#define SRPL_FOREACH_SAFE_LOCKED(_c, _sl, _ENTRY, _tc) \ 59 SLIST_FOREACH_SAFE(_c, _sl, _ENTRY, _tc) 60 61#define SRPL_INSERT_HEAD_LOCKED(_rc, _sl, _e, _ENTRY) \ 62 do { \ 63 (_rc)->srpl_ref((_rc)->srpl_cookie, _e); \ 64 SLIST_INSERT_HEAD(_sl, _e, _ENTRY); \ 65 } while (0) 66 67#define SRPL_REMOVE_LOCKED(_rc, _sl, _e, _type, _ENTRY) \ 68 do { \ 69 SLIST_REMOVE(_sl, _e, _type, _ENTRY); \ 70 ((_rc)->srpl_gc.srp_gc_dtor)((_rc)->srpl_gc.srp_gc_cookie, _e);\ 71 } while (0) 72 73#endif /* _SRP_COMPAT_H_ */ 74