Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern - Add nsems_total and track the use of all semaphor...
details: https://anonhg.NetBSD.org/src/rev/2ba77575aa6e
branches: trunk
changeset: 764330:2ba77575aa6e
user: rmind <rmind%NetBSD.org@localhost>
date: Sat Apr 16 20:39:18 2011 +0000
description:
- Add nsems_total and track the use of all semaphores (not only named ones).
Prevents ksem module from unloading while anonymous semaphore(s) are in use.
- ksem_free: add few asserts.
diffstat:
sys/kern/uipc_sem.c | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
diffs (84 lines):
diff -r f36c6a8bc10c -r 2ba77575aa6e sys/kern/uipc_sem.c
--- a/sys/kern/uipc_sem.c Sat Apr 16 18:41:58 2011 +0000
+++ b/sys/kern/uipc_sem.c Sat Apr 16 20:39:18 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_sem.c,v 1.33 2011/04/15 00:01:48 rmind Exp $ */
+/* $NetBSD: uipc_sem.c,v 1.34 2011/04/16 20:39:18 rmind Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -60,11 +60,12 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.33 2011/04/15 00:01:48 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.34 2011/04/16 20:39:18 rmind Exp $");
#include <sys/param.h>
-#include <sys/systm.h>
#include <sys/kernel.h>
+
+#include <sys/atomic.h>
#include <sys/proc.h>
#include <sys/ksem.h>
#include <sys/syscall.h>
@@ -104,6 +105,7 @@
static kmutex_t ksem_lock __cacheline_aligned;
static LIST_HEAD(,ksem) ksem_head __cacheline_aligned;
+static u_int nsems_total __cacheline_aligned;
static u_int nsems __cacheline_aligned;
static int ksem_sysinit(void);
@@ -141,9 +143,10 @@
{
int error;
- nsems = 0;
mutex_init(&ksem_lock, MUTEX_DEFAULT, IPL_NONE);
LIST_INIT(&ksem_head);
+ nsems_total = 0;
+ nsems = 0;
error = syscall_establish(NULL, ksem_syscalls);
if (error) {
@@ -162,7 +165,11 @@
if (error != 0) {
return error;
}
- if (nsems != 0) {
+ /*
+ * Make sure that no semaphores are in use. Note: semops
+ * must be unused at this point.
+ */
+ if (nsems_total) {
error = syscall_establish(NULL, ksem_syscalls);
KASSERT(error == 0);
return EBUSY;
@@ -296,6 +303,7 @@
ks->ks_uid = kauth_cred_geteuid(uc);
ks->ks_gid = kauth_cred_getegid(uc);
+ atomic_inc_uint(&nsems_total);
*ksret = ks;
return 0;
}
@@ -304,6 +312,9 @@
ksem_free(ksem_t *ks)
{
+ KASSERT(ks->ks_ref == 0);
+ KASSERT(!cv_has_waiters(&ks->ks_cv));
+
if (ks->ks_name) {
KASSERT(ks->ks_namelen > 0);
kmem_free(ks->ks_name, ks->ks_namelen);
@@ -311,6 +322,8 @@
mutex_destroy(&ks->ks_lock);
cv_destroy(&ks->ks_cv);
kmem_free(ks, sizeof(ksem_t));
+
+ atomic_dec_uint(&nsems_total);
}
int
Home |
Main Index |
Thread Index |
Old Index