Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Mar 2018 17:19:59 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r331738 - head/sys/sys
Message-ID:  <201803291719.w2THJxpi011040@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Thu Mar 29 17:19:59 2018
New Revision: 331738
URL: https://svnweb.freebsd.org/changeset/base/331738

Log:
  Have TD_LOCKS_DEC() assert that td_locks is positive.
  
  This makes it easier to catch lock accounting bugs, since the problem
  is otherwise only detected upon a return to user mode (or never, for
  kernel threads).
  
  Reviewed by:	cem
  MFC after:	1 week
  Sponsored by:	Dell EMC Isilon
  Differential Revision:	https://reviews.freebsd.org/D14896

Modified:
  head/sys/sys/proc.h

Modified: head/sys/sys/proc.h
==============================================================================
--- head/sys/sys/proc.h	Thu Mar 29 15:58:49 2018	(r331737)
+++ head/sys/sys/proc.h	Thu Mar 29 17:19:59 2018	(r331738)
@@ -381,7 +381,10 @@ do {									\
 } while (0)
 
 #define	TD_LOCKS_INC(td)	((td)->td_locks++)
-#define	TD_LOCKS_DEC(td)	((td)->td_locks--)
+#define	TD_LOCKS_DEC(td) do {						\
+	KASSERT((td)->td_locks > 0, ("thread %p owns no locks", (td)));	\
+	(td)->td_locks--;						\
+} while (0)
 #else
 #define	THREAD_LOCKPTR_ASSERT(td, lock)
 



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