From 03be85eb11f756414aafedca22f93a3351b727b8 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 27 Dec 2012 00:00:57 +0100 Subject: Optimise dir-lookup's second-lock This should avoid some lock contention. * libdiskfs/dir-lookup.c (diskfs_S_dir_lookup): Before releasing &np->lock to get &dnp->lock safely, try to lock &dnp->lock directly. * libtreefs/dir-lookup.c (_treefs_s_dir_lookup): Likewise. --- libdiskfs/dir-lookup.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libdiskfs') diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c index 1efdf75c..923be033 100644 --- a/libdiskfs/dir-lookup.c +++ b/libdiskfs/dir-lookup.c @@ -310,9 +310,12 @@ diskfs_S_dir_lookup (struct protid *dircred, pthread_mutex_lock (&dnp->lock); else { - pthread_mutex_unlock (&np->lock); - pthread_mutex_lock (&dnp->lock); - pthread_mutex_lock (&np->lock); + if (pthread_mutex_trylock (&dnp->lock)) + { + pthread_mutex_unlock (&np->lock); + pthread_mutex_lock (&dnp->lock); + pthread_mutex_lock (&np->lock); + } } } } -- cgit v1.2.3