Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/rpc simplify more.



details:   https://anonhg.NetBSD.org/src/rev/272dc0e36fd6
branches:  trunk
changeset: 811600:272dc0e36fd6
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Nov 07 03:06:32 2015 +0000

description:
simplify more.

diffstat:

 lib/libc/rpc/svc_fdset.c |  65 +++++++++++++++++------------------------------
 1 files changed, 24 insertions(+), 41 deletions(-)

diffs (147 lines):

diff -r b3dac35bf565 -r 272dc0e36fd6 lib/libc/rpc/svc_fdset.c
--- a/lib/libc/rpc/svc_fdset.c  Sat Nov 07 00:42:04 2015 +0000
+++ b/lib/libc/rpc/svc_fdset.c  Sat Nov 07 03:06:32 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svc_fdset.c,v 1.5 2015/11/07 00:42:04 christos Exp $   */
+/*     $NetBSD: svc_fdset.c,v 1.6 2015/11/07 03:06:32 christos Exp $   */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: svc_fdset.c,v 1.5 2015/11/07 00:42:04 christos Exp $");
+__RCSID("$NetBSD: svc_fdset.c,v 1.6 2015/11/07 03:06:32 christos Exp $");
 
 
 #include "reentrant.h"
@@ -172,6 +172,9 @@
 {
        struct svc_fdset *fds;
 
+       if (!__isthreaded || fdsetkey == -2)
+               return svc_fdset_resize(fd, &__svc_fdset);
+
        if (fdsetkey == -1)
                thr_keycreate(&fdsetkey, svc_fdset_free);
 
@@ -198,16 +201,6 @@
        return svc_fdset_resize(fd, fds);
 }
 
-static struct svc_fdset *
-svc_fdset_get_internal(int fd)
-{
-       if (!__isthreaded || fdsetkey == -2)
-               return svc_fdset_resize(fd, &__svc_fdset);
-
-       return svc_fdset_alloc(fd);
-}
-
-
 /* allow each thread to have their own copy */
 void
 svc_fdset_init(int flags)
@@ -221,18 +214,20 @@
 svc_fdset_zero(void)
 {
        DPRINTF("zero");
-       struct svc_fdset *fds = svc_fdset_get_internal(0);
+       struct svc_fdset *fds = svc_fdset_alloc(0);
        memset(fds->fdset, 0, fds->fdsize);
-       fds->fdmax = 0;
+       fds->fdmax = -1;
 }
 
 void
 svc_fdset_set(int fd)
 {
-       struct svc_fdset *fds = svc_fdset_get_internal(fd);
+       struct svc_fdset *fds = svc_fdset_alloc(fd);
+
        FD_SET(fd, fds->fdset);
        if (fd > fds->fdmax)
                fds->fdmax = fd;
+
        DPRINTF_FDSET(fds, "%d", fd);
 
        svc_fdset_sanitize(fds);
@@ -241,19 +236,22 @@
 int
 svc_fdset_isset(int fd)
 {
-       struct svc_fdset *fds = svc_fdset_get_internal(fd);
-       svc_fdset_sanitize(fds);
+       struct svc_fdset *fds = svc_fdset_alloc(fd);
+
        DPRINTF_FDSET(fds, "%d", fd);
+
        return FD_ISSET(fd, fds->fdset);
 }
 
 void
 svc_fdset_clr(int fd)
 {
-       struct svc_fdset *fds = svc_fdset_get_internal(fd);
+       struct svc_fdset *fds = svc_fdset_alloc(fd);
+
        FD_CLR(fd, fds->fdset);
+       DPRINTF_FDSET(fds, "%d", fd);
+
        svc_fdset_sanitize(fds);
-       DPRINTF_FDSET(fds, "%d", fd);
 }
 
 fd_set *
@@ -271,43 +269,28 @@
 fd_set *
 svc_fdset_get(void)
 {
-       struct svc_fdset *fds = svc_fdset_get_internal(0);
-       svc_fdset_sanitize(fds);
+       struct svc_fdset *fds = svc_fdset_alloc(0);
 
        DPRINTF_FDSET(fds, "get");
+       svc_fdset_sanitize(fds);
        return fds->fdset;
 }
 
 int *
 svc_fdset_getmax(void)
 {
-       struct svc_fdset *fds;
+       struct svc_fdset *fds = svc_fdset_alloc(0);
 
-       if (!__isthreaded || fdsetkey == -2) {
-               svc_fdset_sanitize(&__svc_fdset);
-               return &__svc_fdset.fdmax;
-       }
-               
-       fds = svc_fdset_alloc(0);
-       if (fds == NULL)
-               return NULL;
+       DPRINTF_FDSET(fds, "getmax");
+       svc_fdset_sanitize(fds);
        return &fds->fdmax;
 }
 
 int
 svc_fdset_getsize(int fd)
 {
-       struct svc_fdset *fds;
+       struct svc_fdset *fds = svc_fdset_alloc(fd);
 
-       if (!__isthreaded || fdsetkey == -2) {
-               if (svc_fdset_resize(fd, &__svc_fdset) == NULL)
-                       return -1;
-               else
-                       return __svc_fdset.fdsize;
-       }
-
-       fds = svc_fdset_alloc(fd);
-       if (fds == NULL)
-               return -1;
+       DPRINTF_FDSET(fds, "getsize");
        return fds->fdsize;
 }



Home | Main Index | Thread Index | Old Index