GSoC 2016: Charles Cui: add SEM_NSEMS_MAX

This commit is contained in:
christos 2016-06-10 23:24:33 +00:00
parent da2bfb7944
commit 0196f35dd1
6 changed files with 23 additions and 9 deletions

View File

@ -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

View File

@ -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 @@ and its
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

View File

@ -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 @@ yesno: if (sysctl(mib, mib_len, &value, &len, NULL, 0) == -1)
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);

View File

@ -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 @@ MODULE(MODULE_CLASS_MISC, ksem, NULL);
#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 @@ ksem_create(lwp_t *l, const char *name, ksem_t **ksret, mode_t mode, u_int val)
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 @@ ksem_free(ksem_t *ks)
kmem_free(ks, sizeof(ksem_t));
atomic_dec_uint(&nsems_total);
atomic_dec_uint(&curproc->p_nsems);
}
int

View File

@ -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 proc {
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

View File

@ -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