Source-Changes-HG archive

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

[src/trunk]: src GSoC 2016: Charles Cui: add SEM_NSEMS_MAX



details:   https://anonhg.NetBSD.org/src/rev/56f661187f13
branches:  trunk
changeset: 815987:56f661187f13
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jun 10 23:24:33 2016 +0000

description:
GSoC 2016: Charles Cui: add SEM_NSEMS_MAX

diffstat:

 include/limits.h       |   3 ++-
 lib/libc/gen/sysconf.3 |   5 ++++-
 lib/libc/gen/sysconf.c |   6 ++++--
 sys/kern/uipc_sem.c    |  11 +++++++++--
 sys/sys/proc.h         |   3 ++-
 sys/sys/unistd.h       |   4 ++--
 6 files changed, 23 insertions(+), 9 deletions(-)

diffs (144 lines):

diff -r 275c2f597000 -r 56f661187f13 include/limits.h
--- a/include/limits.h  Fri Jun 10 23:07:52 2016 +0000
+++ b/include/limits.h  Fri Jun 10 23:24:33 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: limits.h,v 1.36 2016/03/08 05:02:55 christos Exp $     */
+/*     $NetBSD: limits.h,v 1.37 2016/06/10 23:24:33 christos Exp $     */
 
 /*
  * Copyright (c) 1988, 1993
@@ -93,6 +93,7 @@
 #define        PTHREAD_THREADS_MAX             _POSIX_THREAD_THREADS_MAX
 
 #define        _POSIX_TIMER_MAX        32
+#define        _POSIX_SEM_NSEMS_MAX    256
 #define        _POSIX_TTY_NAME_MAX     9
 #define        _POSIX_TZNAME_MAX       6
 
diff -r 275c2f597000 -r 56f661187f13 lib/libc/gen/sysconf.3
--- a/lib/libc/gen/sysconf.3    Fri Jun 10 23:07:52 2016 +0000
+++ b/lib/libc/gen/sysconf.3    Fri Jun 10 23:24:33 2016 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sysconf.3,v 1.45 2016/02/26 17:13:01 christos Exp $
+.\"    $NetBSD: sysconf.3,v 1.46 2016/06/10 23:24:33 christos Exp $
 .\"
 .\" Copyright (c) 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -149,6 +149,9 @@
 Semaphores
 option to which the system attempts to conform,
 otherwise \-1.
+.It Li _SC_SEM_NSEMS_MAX
+The maximum number of semaphores that one process can have open at a time,
+otherwise \-1.
 .It Li _SC_SHELL
 Return 1 if
 .Tn POSIX
diff -r 275c2f597000 -r 56f661187f13 lib/libc/gen/sysconf.c
--- a/lib/libc/gen/sysconf.c    Fri Jun 10 23:07:52 2016 +0000
+++ b/lib/libc/gen/sysconf.c    Fri Jun 10 23:24:33 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysconf.c,v 1.37 2016/02/26 17:13:01 christos Exp $    */
+/*     $NetBSD: sysconf.c,v 1.38 2016/06/10 23:24:33 christos Exp $    */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)sysconf.c  8.2 (Berkeley) 3/20/94";
 #else
-__RCSID("$NetBSD: sysconf.c,v 1.37 2016/02/26 17:13:01 christos Exp $");
+__RCSID("$NetBSD: sysconf.c,v 1.38 2016/06/10 23:24:33 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -420,6 +420,8 @@
                return pathconf(_PATH_DEV, _PC_NAME_MAX);
        case _SC_TIMER_MAX:
                return _POSIX_TIMER_MAX;
+       case _SC_SEM_NSEMS_MAX:
+               return _POSIX_SEM_NSEMS_MAX;
        default:
                errno = EINVAL;
                return (-1);
diff -r 275c2f597000 -r 56f661187f13 sys/kern/uipc_sem.c
--- a/sys/kern/uipc_sem.c       Fri Jun 10 23:07:52 2016 +0000
+++ b/sys/kern/uipc_sem.c       Fri Jun 10 23:24:33 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_sem.c,v 1.45 2016/04/24 19:48:29 dholland Exp $   */
+/*     $NetBSD: uipc_sem.c,v 1.46 2016/06/10 23:24:33 christos Exp $   */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.45 2016/04/24 19:48:29 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.46 2016/06/10 23:24:33 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -87,6 +87,7 @@
 
 #define        SEM_MAX_NAMELEN         14
 
+#define        SEM_NSEMS_MAX           256
 #define        KS_UNLINKED             0x01
 
 static kmutex_t                ksem_lock       __cacheline_aligned;
@@ -333,6 +334,11 @@
                len = 0;
        }
 
+       if (atomic_inc_uint_nv(&l->l_proc->p_nsems) > SEM_NSEMS_MAX) {
+               atomic_dec_uint(&l->l_proc->p_nsems);
+               return -1;
+       }
+
        ks = kmem_zalloc(sizeof(ksem_t), KM_SLEEP);
        mutex_init(&ks->ks_lock, MUTEX_DEFAULT, IPL_NONE);
        cv_init(&ks->ks_cv, "psem");
@@ -366,6 +372,7 @@
        kmem_free(ks, sizeof(ksem_t));
 
        atomic_dec_uint(&nsems_total);
+       atomic_dec_uint(&curproc->p_nsems);     
 }
 
 int
diff -r 275c2f597000 -r 56f661187f13 sys/sys/proc.h
--- a/sys/sys/proc.h    Fri Jun 10 23:07:52 2016 +0000
+++ b/sys/sys/proc.h    Fri Jun 10 23:24:33 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proc.h,v 1.330 2016/04/27 21:15:40 christos Exp $      */
+/*     $NetBSD: proc.h,v 1.331 2016/06/10 23:24:33 christos Exp $      */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -305,6 +305,7 @@
        struct lcproc   *p_lwpctl;      /* p, a: _lwp_ctl() information */
        pid_t           p_ppid;         /* :: cached parent pid */
        pid_t           p_fpid;         /* :: forked pid */
+       u_int           p_nsems;        /* Count of semaphores */
 
 /*
  * End area that is zeroed on creation
diff -r 275c2f597000 -r 56f661187f13 sys/sys/unistd.h
--- a/sys/sys/unistd.h  Fri Jun 10 23:07:52 2016 +0000
+++ b/sys/sys/unistd.h  Fri Jun 10 23:24:33 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: unistd.h,v 1.56 2016/02/26 17:10:41 christos Exp $     */
+/*     $NetBSD: unistd.h,v 1.57 2016/06/10 23:24:33 christos Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -308,7 +308,7 @@
 #define        _SC_SHARED_MEMORY_OBJECTS       87
 
 #define        _SC_TIMER_MAX                   88
-
+#define        _SC_SEM_NSEMS_MAX               89
 
 /* Extensions found in Solaris and Linux. */
 #define        _SC_PHYS_PAGES          121



Home | Main Index | Thread Index | Old Index