Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Mar 2003 12:55:11 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 26393 for review
Message-ID:  <200303052055.h25KtB2Y098168@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=26393

Change 26393 by jhb@jhb_laptop on 2003/03/05 12:54:38

	Teach mtx_trylock() to recurse.  No hope of inlining this thing
	in the future now.  Too much of a pig.

Affected files ...

.. //depot/projects/smpng/sys/kern/kern_mutex.c#61 edit

Differences ...

==== //depot/projects/smpng/sys/kern/kern_mutex.c#61 (text+ko) ====

@@ -454,10 +454,8 @@
 
 /*
  * The important part of mtx_trylock{,_flags}()
- * Tries to acquire lock `m.' We do NOT handle recursion here.  If this
- * function is called on a recursed mutex, it will return failure and
- * will not recursively acquire the lock.  You are expected to know what
- * you are doing.
+ * Tries to acquire lock `m.'  If this function is called on a mutex that
+ * is already owned, it will recursively acquire the lock.
  */
 int
 _mtx_trylock(struct mtx *m, int opts, const char *file, int line)
@@ -466,7 +464,12 @@
 
 	MPASS(curthread != NULL);
 
-	rval = _obtain_lock(m, curthread);
+	if (mtx_owned(m)) {
+		m->mtx_recurse++;
+		atomic_set_ptr(&m->mtx_lock, MTX_RECURSED);
+		rval = 1;
+	} else
+		rval = _obtain_lock(m, curthread);
 
 	LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line);
 	if (rval)

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




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