From: mvs Date: Sat, 26 Nov 2022 17:52:35 +0000 (+0000) Subject: Turn sowriteable(), sballoc() and sbfree() macro to inline functions. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d452b926f142c4271bac299168cd77e2ced42046;p=openbsd Turn sowriteable(), sballoc() and sbfree() macro to inline functions. soreadable() is already presented as inline function, but corresponding sowriteable() is still macro. Also it's no reason to keep sballoc() and sbfree() as macro. The first argument of sballoc() and sbfree() is not used, but keep it for a while. ok kn@ bluhm@ --- diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index cbabe0b66bd..0109c076039 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.58 2022/10/17 14:49:02 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.59 2022/11/26 17:52:35 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -53,6 +53,9 @@ * described below. */ +#ifndef _SYS_PROTOSW_H_ +#define _SYS_PROTOSW_H_ + struct mbuf; struct sockaddr; struct socket; @@ -413,3 +416,5 @@ pru_connect2(struct socket *so1, struct socket *so2) } #endif + +#endif /* _SYS_PROTOSW_H_ */ diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 0e9030059c1..3e3f8757e7b 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socketvar.h,v 1.111 2022/10/03 16:43:52 bluhm Exp $ */ +/* $OpenBSD: socketvar.h,v 1.112 2022/11/26 17:52:35 mvs Exp $ */ /* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */ /*- @@ -160,6 +160,7 @@ struct socket { #ifdef _KERNEL +#include #include void soassertlocked(struct socket *); @@ -229,31 +230,39 @@ soreadable(struct socket *so) } /* can we write something to so? */ -#define sowriteable(so) \ - ((sbspace((so), &(so)->so_snd) >= (so)->so_snd.sb_lowat && \ - (((so)->so_state & SS_ISCONNECTED) || \ - ((so)->so_proto->pr_flags & PR_CONNREQUIRED)==0)) || \ - ((so)->so_state & SS_CANTSENDMORE) || (so)->so_error) +static inline int +sowriteable(struct socket *so) +{ + soassertlocked(so); + return ((sbspace(so, &so->so_snd) >= so->so_snd.sb_lowat && + ((so->so_state & SS_ISCONNECTED) || + (so->so_proto->pr_flags & PR_CONNREQUIRED)==0)) || + (so->so_state & SS_CANTSENDMORE) || so->so_error); +} /* adjust counters in sb reflecting allocation of m */ -#define sballoc(so, sb, m) do { \ - (sb)->sb_cc += (m)->m_len; \ - if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \ - (sb)->sb_datacc += (m)->m_len; \ - (sb)->sb_mbcnt += MSIZE; \ - if ((m)->m_flags & M_EXT) \ - (sb)->sb_mbcnt += (m)->m_ext.ext_size; \ -} while (/* CONSTCOND */ 0) +static inline void +sballoc(struct socket *so, struct sockbuf *sb, struct mbuf *m) +{ + sb->sb_cc += m->m_len; + if (m->m_type != MT_CONTROL && m->m_type != MT_SONAME) + sb->sb_datacc += m->m_len; + sb->sb_mbcnt += MSIZE; + if (m->m_flags & M_EXT) + sb->sb_mbcnt += m->m_ext.ext_size; +} /* adjust counters in sb reflecting freeing of m */ -#define sbfree(so, sb, m) do { \ - (sb)->sb_cc -= (m)->m_len; \ - if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \ - (sb)->sb_datacc -= (m)->m_len; \ - (sb)->sb_mbcnt -= MSIZE; \ - if ((m)->m_flags & M_EXT) \ - (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \ -} while (/* CONSTCOND */ 0) +static inline void +sbfree(struct socket *so, struct sockbuf *sb, struct mbuf *m) +{ + sb->sb_cc -= m->m_len; + if (m->m_type != MT_CONTROL && m->m_type != MT_SONAME) + sb->sb_datacc -= m->m_len; + sb->sb_mbcnt -= MSIZE; + if (m->m_flags & M_EXT) + sb->sb_mbcnt -= m->m_ext.ext_size; +} /* * Set lock on sockbuf sb; sleep if lock is already held.