Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Jul 2014 21:12:59 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r268634 - in head/sys: kern sys
Message-ID:  <201407142112.s6ELCx7n000288@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Mon Jul 14 21:12:59 2014
New Revision: 268634
URL: http://svnweb.freebsd.org/changeset/base/268634

Log:
  Manage struct sigacts refcnt with atomics instead of a mutex.
  
  MFC after:	1 week

Modified:
  head/sys/kern/kern_sig.c
  head/sys/sys/signalvar.h

Modified: head/sys/kern/kern_sig.c
==============================================================================
--- head/sys/kern/kern_sig.c	Mon Jul 14 20:58:57 2014	(r268633)
+++ head/sys/kern/kern_sig.c	Mon Jul 14 21:12:59 2014	(r268634)
@@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/mutex.h>
+#include <sys/refcount.h>
 #include <sys/namei.h>
 #include <sys/proc.h>
 #include <sys/procdesc.h>
@@ -3422,21 +3423,17 @@ void
 sigacts_free(struct sigacts *ps)
 {
 
-	mtx_lock(&ps->ps_mtx);
-	ps->ps_refcnt--;
-	if (ps->ps_refcnt == 0) {
-		mtx_destroy(&ps->ps_mtx);
-		free(ps, M_SUBPROC);
-	} else
-		mtx_unlock(&ps->ps_mtx);
+	if (refcount_release(&ps->ps_refcnt) == 0)
+		return;
+	mtx_destroy(&ps->ps_mtx);
+	free(ps, M_SUBPROC);
 }
 
 struct sigacts *
 sigacts_hold(struct sigacts *ps)
 {
-	mtx_lock(&ps->ps_mtx);
-	ps->ps_refcnt++;
-	mtx_unlock(&ps->ps_mtx);
+
+	refcount_acquire(&ps->ps_refcnt);
 	return (ps);
 }
 

Modified: head/sys/sys/signalvar.h
==============================================================================
--- head/sys/sys/signalvar.h	Mon Jul 14 20:58:57 2014	(r268633)
+++ head/sys/sys/signalvar.h	Mon Jul 14 21:12:59 2014	(r268634)
@@ -63,7 +63,7 @@ struct sigacts {
 	sigset_t ps_osigset;		/* Signals using <= 3.x osigset_t. */
 	sigset_t ps_usertramp;		/* SunOS compat; libc sigtramp. XXX */
 	int	ps_flag;
-	int	ps_refcnt;
+	u_int	ps_refcnt;
 	struct mtx ps_mtx;
 };
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407142112.s6ELCx7n000288>