Index: src/share/man/man9/sx.9 =================================================================== --- src/share/man/man9/sx.9 (revision 112) +++ src/share/man/man9/sx.9 (revision 116) @@ -43,6 +43,7 @@ .Nm sx_downgrade , .Nm sx_assert , .Nm sx_unlock , +.Nm sx_xlocked , .Nm SX_SYSINIT .Nd kernel shared/exclusive lock .Sh SYNOPSIS @@ -71,6 +72,8 @@ .Fn sx_downgrade "struct sx *sx" .Ft void .Fn sx_assert "struct sx *sx" "int what" +.Ft int +.Fn sx_xlocked "struct sx *sx" .\" .Ss sx utility macros .Fn sx_unlock "struct sx *sx" @@ -166,6 +169,10 @@ by the first argument. .El .Pp +.Fn sx_xlocked +will return non-zero if the current process holds the exclusive lock; +otherwise, it will return zero. +.Pp For ease of programming, .Fn sx_unlock is provided as a macro frontend to the respective functions, Index: src/share/man/man9/Makefile =================================================================== --- src/share/man/man9/Makefile (revision 112) +++ src/share/man/man9/Makefile (revision 116) @@ -883,7 +883,8 @@ sx.9 sx_try_upgrade.9 \ sx.9 sx_try_xlock.9 \ sx.9 sx_xlock.9 \ - sx.9 sx_xunlock.9 + sx.9 sx_xunlock.9 \ + sx.9 sx_xlocked.9 MLINKS+=sysctl_add_oid.9 SYSCTL_ADD_INT.9 \ sysctl_add_oid.9 SYSCTL_ADD_LONG.9 \ sysctl_add_oid.9 SYSCTL_ADD_NODE.9 \ Index: src/sys/kern/kern_sx.c =================================================================== --- src/sys/kern/kern_sx.c (revision 112) +++ src/sys/kern/kern_sx.c (revision 116) @@ -367,3 +367,15 @@ } } #endif /* INVARIANT_SUPPORT */ + +int +sx_xlocked(struct sx *sx) +{ + mtx_lock(sx->sx_lock); + if (sx->sx_xholder == curthread) { + mtx_unlock(sx->sx_lock); + return (1); + } + mtx_unlock(sx->sx_lock); + return (0); +} Index: src/sys/sys/sx.h =================================================================== --- src/sys/sys/sx.h (revision 112) +++ src/sys/sys/sx.h (revision 116) @@ -60,6 +60,7 @@ #ifdef INVARIANT_SUPPORT void _sx_assert(struct sx *sx, int what, const char *file, int line); #endif +int sx_xlocked(struct sx *sx); struct sx_args { struct sx *sa_sx;