summaryrefslogtreecommitdiffstats
path: root/sys/sys/_sx.h
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2007-03-31 23:23:42 +0000
committerjhb <jhb@FreeBSD.org>2007-03-31 23:23:42 +0000
commitb0b93a3c55b874a04a163db8dcf6af0b7e28b2e4 (patch)
tree6f71182be4d218a6130d92f4c3455591243f0019 /sys/sys/_sx.h
parent7f18b608045d45d3d89e8cbaa7710fcbbc4d7eab (diff)
downloadFreeBSD-src-b0b93a3c55b874a04a163db8dcf6af0b7e28b2e4.zip
FreeBSD-src-b0b93a3c55b874a04a163db8dcf6af0b7e28b2e4.tar.gz
Optimize sx locks to use simple atomic operations for the common cases of
obtaining and releasing shared and exclusive locks. The algorithms for manipulating the lock cookie are very similar to that rwlocks. This patch also adds support for exclusive locks using the same algorithm as mutexes. A new sx_init_flags() function has been added so that optional flags can be specified to alter a given locks behavior. The flags include SX_DUPOK, SX_NOWITNESS, SX_NOPROFILE, and SX_QUITE which are all identical in nature to the similar flags for mutexes. Adaptive spinning on select locks may be enabled by enabling the ADAPTIVE_SX kernel option. Only locks initialized with the SX_ADAPTIVESPIN flag via sx_init_flags() will adaptively spin. The common cases for sx_slock(), sx_sunlock(), sx_xlock(), and sx_xunlock() are now performed inline in non-debug kernels. As a result, <sys/sx.h> now requires <sys/lock.h> to be included prior to <sys/sx.h>. The new kernel option SX_NOINLINE can be used to disable the aforementioned inlining in non-debug kernels. The size of struct sx has changed, so the kernel ABI is probably greatly disturbed. MFC after: 1 month Submitted by: attilio Tested by: kris, pjd
Diffstat (limited to 'sys/sys/_sx.h')
-rw-r--r--sys/sys/_sx.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/sys/sys/_sx.h b/sys/sys/_sx.h
new file mode 100644
index 0000000..0d0351c
--- /dev/null
+++ b/sys/sys/_sx.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2007 Attilio Rao <attilio@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SYS__SX_H_
+#define _SYS__SX_H_
+
+/*
+ * Shared/exclusive lock main structure definition.
+ */
+struct sx {
+ struct lock_object lock_object;
+ volatile uintptr_t sx_lock;
+ volatile unsigned sx_recurse;
+};
+
+#endif /* !_SYS__SX_H_ */
OpenPOWER on IntegriCloud