On Mon, Nov 14, 2022 at 02:14:27PM +0300, Vitaliy Makkoveev wrote:
> We have soreadable() already presented as inline function, but
> corresponding sowriteable() is still macro. Also it's no reason to keep
> sballoc() and sbfree() as macro.

This reads as an improvement to me.

sballoc() and sbfree()'s struct socket *so argument is entirely unused,
can it be removed?

> 
> Index: sys/sys/protosw.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/protosw.h,v
> retrieving revision 1.58
> diff -u -p -r1.58 protosw.h
> --- sys/sys/protosw.h 17 Oct 2022 14:49:02 -0000      1.58
> +++ sys/sys/protosw.h 14 Nov 2022 11:07:29 -0000
> @@ -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 
>  }
>  
>  #endif
> +
> +#endif /* _SYS_PROTOSW_H_ */
> Index: sys/sys/socketvar.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/socketvar.h,v
> retrieving revision 1.111
> diff -u -p -r1.111 socketvar.h
> --- sys/sys/socketvar.h       3 Oct 2022 16:43:52 -0000       1.111
> +++ sys/sys/socketvar.h       14 Nov 2022 11:07:29 -0000
> @@ -160,6 +160,7 @@ struct socket {
>  
>  #ifdef _KERNEL
>  
> +#include <sys/protosw.h>
>  #include <lib/libkern/libkern.h>
>  
>  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.
> 

Reply via email to