diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-12-27 00:00:57 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-12-27 00:00:57 +0100 |
commit | 03be85eb11f756414aafedca22f93a3351b727b8 (patch) | |
tree | 8657bee4e525bdc1f8fe640d44055dcca8857dc2 /libdiskfs/dir-lookup.c | |
parent | 07440b75bcbd20056c11f2375d3aa765788af034 (diff) |
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.
Diffstat (limited to 'libdiskfs/dir-lookup.c')
-rw-r--r-- | libdiskfs/dir-lookup.c | 9 |
1 files changed, 6 insertions, 3 deletions
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); + } } } } |