PERFORCE change 31014 for review
Peter Wemm
peter at FreeBSD.org
Mon May 12 09:09:44 PDT 2003
http://perforce.freebsd.org/chv.cgi?CH=31014
Change 31014 by peter at peter_daintree on 2003/05/12 09:08:44
IFC @31013
Affected files ...
.. //depot/projects/hammer/etc/network.subr#2 integrate
.. //depot/projects/hammer/etc/pccard_ether#4 integrate
.. //depot/projects/hammer/etc/rc.d/network_ipv6#4 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_kern.c#3 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_mutex.c#3 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_private.h#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_sig.c#3 integrate
.. //depot/projects/hammer/release/alpha/drivers.conf#7 integrate
.. //depot/projects/hammer/sys/dev/ata/ata-card.c#6 integrate
.. //depot/projects/hammer/sys/kern/link_elf.c#12 integrate
.. //depot/projects/hammer/sys/kern/vfs_subr.c#15 integrate
Differences ...
==== //depot/projects/hammer/etc/network.subr#2 (text+ko) ====
@@ -22,7 +22,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $FreeBSD: src/etc/network.subr,v 1.146 2003/04/18 17:51:53 mtm Exp $
+# $FreeBSD: src/etc/network.subr,v 1.147 2003/05/12 11:36:49 ume Exp $
#
#
@@ -212,3 +212,299 @@
esac
return 0
}
+
+hexdigit()
+{
+ if [ $1 -lt 10 ]; then
+ echo $1
+ else
+ case $1 in
+ 10) echo a ;;
+ 11) echo b ;;
+ 12) echo c ;;
+ 13) echo d ;;
+ 14) echo e ;;
+ 15) echo f ;;
+ esac
+ fi
+}
+
+hexprint()
+{
+ val=$1
+ str=''
+
+ dig=`hexdigit $((${val} & 15))`
+ str=${dig}${str}
+ val=$((${val} >> 4))
+ while [ ${val} -gt 0 ]; do
+ dig=`hexdigit $((${val} & 15))`
+ str=${dig}${str}
+ val=$((${val} >> 4))
+ done
+
+ echo ${str}
+}
+
+# Setup the interfaces for IPv6
+network6_interface_setup()
+{
+ interfaces=$*
+ rtsol_interfaces=''
+ case ${ipv6_gateway_enable} in
+ [Yy][Ee][Ss])
+ rtsol_available=no
+ ;;
+ *)
+ rtsol_available=yes
+ ;;
+ esac
+ for i in $interfaces; do
+ rtsol_interface=yes
+ eval prefix=\$ipv6_prefix_$i
+ if [ -n "${prefix}" ]; then
+ rtsol_available=no
+ rtsol_interface=no
+ laddr=`network6_getladdr $i`
+ hostid=`expr "${laddr}" : 'fe80::\(.*\)%\(.*\)'`
+ for j in ${prefix}; do
+ address=$j\:${hostid}
+ ifconfig $i inet6 ${address} prefixlen 64 alias
+
+ case ${ipv6_gateway_enable} in
+ [Yy][Ee][Ss])
+ # subnet-router anycast address
+ # (rfc2373)
+ ifconfig $i inet6 $j:: prefixlen 64 \
+ alias anycast
+ ;;
+ esac
+ done
+ fi
+ eval ipv6_ifconfig=\$ipv6_ifconfig_$i
+ if [ -n "${ipv6_ifconfig}" ]; then
+ rtsol_available=no
+ rtsol_interface=no
+ ifconfig $i inet6 ${ipv6_ifconfig} alias
+ fi
+
+ if [ ${rtsol_available} = yes -a ${rtsol_interface} = yes ]
+ then
+ case ${i} in
+ lo0|gif[0-9]*|stf[0-9]*|faith[0-9]*|lp[0-9]*|sl[0-9]*|tun[0-9]*)
+ ;;
+ *)
+ rtsol_interfaces="${rtsol_interfaces} ${i}"
+ ;;
+ esac
+ else
+ ifconfig $i inet6
+ fi
+ done
+
+ if [ ${rtsol_available} = yes -a -n "${rtsol_interfaces}" ]; then
+ # Act as endhost - automatically configured.
+ # You can configure only single interface, as
+ # specification assumes that autoconfigured host has
+ # single interface only.
+ sysctl net.inet6.ip6.accept_rtadv=1
+ set ${rtsol_interfaces}
+ ifconfig $1 up
+ rtsol $1
+ fi
+
+ for i in $interfaces; do
+ alias=0
+ while : ; do
+ eval ipv6_ifconfig=\$ipv6_ifconfig_${i}_alias${alias}
+ if [ -z "${ipv6_ifconfig}" ]; then
+ break;
+ fi
+ ifconfig $i inet6 ${ipv6_ifconfig} alias
+ alias=$((${alias} + 1))
+ done
+ done
+}
+
+# Setup IPv6 to IPv4 mapping
+network6_stf_setup()
+{
+ case ${stf_interface_ipv4addr} in
+ [Nn][Oo] | '')
+ ;;
+ *)
+ # assign IPv6 addr and interface route for 6to4 interface
+ stf_prefixlen=$((16+${stf_interface_ipv4plen:-0}))
+ OIFS="$IFS"
+ IFS=".$IFS"
+ set ${stf_interface_ipv4addr}
+ IFS="$OIFS"
+ hexfrag1=`hexprint $(($1*256 + $2))`
+ hexfrag2=`hexprint $(($3*256 + $4))`
+ ipv4_in_hexformat="${hexfrag1}:${hexfrag2}"
+ case ${stf_interface_ipv6_ifid} in
+ [Aa][Uu][Tt][Oo] | '')
+ for i in ${ipv6_network_interfaces}; do
+ laddr=`network6_getladdr ${i}`
+ case ${laddr} in
+ '')
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+ stf_interface_ipv6_ifid=`expr "${laddr}" : \
+ 'fe80::\(.*\)%\(.*\)'`
+ case ${stf_interface_ipv6_ifid} in
+ '')
+ stf_interface_ipv6_ifid=0:0:0:1
+ ;;
+ esac
+ ;;
+ esac
+ ifconfig stf0 create >/dev/null 2>&1
+ ifconfig stf0 inet6 2002:${ipv4_in_hexformat}:${stf_interface_ipv6_slaid:-0}:${stf_interface_ipv6_ifid} \
+ prefixlen ${stf_prefixlen}
+ # disallow packets to malicious 6to4 prefix
+ route add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
+ route add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
+ route add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
+ route add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
+ ;;
+ esac
+}
+
+# Setup static routes
+network6_static_routes_setup()
+{
+ # Set up any static routes.
+ case ${ipv6_defaultrouter} in
+ [Nn][Oo] | '')
+ ;;
+ *)
+ ipv6_static_routes="default ${ipv6_static_routes}"
+ ipv6_route_default="default ${ipv6_defaultrouter}"
+ ;;
+ esac
+ case ${ipv6_static_routes} in
+ [Nn][Oo] | '')
+ ;;
+ *)
+ for i in ${ipv6_static_routes}; do
+ eval ipv6_route_args=\$ipv6_route_${i}
+ route add -inet6 ${ipv6_route_args}
+ done
+ ;;
+ esac
+}
+
+# Setup faith
+network6_faith_setup()
+{
+ case ${ipv6_faith_prefix} in
+ [Nn][Oo] | '')
+ ;;
+ *)
+ sysctl net.inet6.ip6.keepfaith=1
+ ifconfig faith0 create >/dev/null 2>&1
+ ifconfig faith0 up
+ for prefix in ${ipv6_faith_prefix}; do
+ prefixlen=`expr "${prefix}" : ".*/\(.*\)"`
+ case ${prefixlen} in
+ '')
+ prefixlen=96
+ ;;
+ *)
+ prefix=`expr "${prefix}" : \
+ "\(.*\)/${prefixlen}"`
+ ;;
+ esac
+ route add -inet6 ${prefix} -prefixlen ${prefixlen} ::1
+ route change -inet6 ${prefix} -prefixlen ${prefixlen} \
+ -ifp faith0
+ done
+ ;;
+ esac
+}
+
+# Install the "default interface" to kernel, which will be used
+# as the default route when there's no router.
+network6_default_interface_setup()
+{
+ # Choose IPv6 default interface if it is not clearly specified.
+ case ${ipv6_default_interface} in
+ '')
+ for i in ${ipv6_network_interfaces}; do
+ case $i in
+ lo0|faith[0-9]*)
+ continue
+ ;;
+ esac
+ laddr=`network6_getladdr $i exclude_tentative`
+ case ${laddr} in
+ '')
+ ;;
+ *)
+ ipv6_default_interface=$i
+ break
+ ;;
+ esac
+ done
+ ;;
+ esac
+
+ # Disallow unicast packets without outgoing scope identifiers,
+ # or route such packets to a "default" interface, if it is specified.
+ route add -inet6 fe80:: -prefixlen 10 ::1 -reject
+ case ${ipv6_default_interface} in
+ [Nn][Oo] | '')
+ route add -inet6 ff02:: -prefixlen 16 ::1 -reject
+ ;;
+ *)
+ laddr=`network6_getladdr ${ipv6_default_interface}`
+ route add -inet6 ff02:: ${laddr} -prefixlen 16 -interface \
+ -cloning
+
+ # Disable installing the default interface with the
+ # case net.inet6.ip6.forwarding=0 and
+ # net.inet6.ip6.accept_rtadv=0, due to avoid conflict
+ # between the default router list and the manual
+ # configured default route.
+ case ${ipv6_gateway_enable} in
+ [Yy][Ee][Ss])
+ ;;
+ *)
+ if [ `sysctl -n net.inet6.ip6.accept_rtadv` -eq 1 ]
+ then
+ ndp -I ${ipv6_default_interface}
+ fi
+ ;;
+ esac
+ ;;
+ esac
+}
+
+network6_getladdr()
+{
+ ifconfig $1 2>/dev/null | while read proto addr rest; do
+ case ${proto} in
+ inet6)
+ case ${addr} in
+ fe80::*)
+ if [ -z "$2" ]; then
+ echo ${addr}
+ return
+ fi
+ case ${rest} in
+ *tentative*)
+ continue
+ ;;
+ *)
+ echo ${addr}
+ return
+ esac
+ esac
+ esac
+ done
+}
==== //depot/projects/hammer/etc/pccard_ether#4 (text+ko) ====
@@ -1,6 +1,6 @@
#!/bin/sh -
#
-# $FreeBSD: src/etc/pccard_ether,v 1.29 2003/05/05 19:06:46 ume Exp $
+# $FreeBSD: src/etc/pccard_ether,v 1.30 2003/05/12 11:36:49 ume Exp $
#
# pccard_ether interfacename [start|stop] [ifconfig option]
#
@@ -134,8 +134,8 @@
# IPv6 setup
case ${ipv6_enable} in
[Yy][Ee][Ss])
- if [ -r /etc/rc.d/network_ipv6 ]; then
- . /etc/rc.d/network_ipv6
+ if [ -r /etc/network.subr ]; then
+ . /etc/network.subr
network6_interface_setup ${interface}
fi
;;
==== //depot/projects/hammer/etc/rc.d/network_ipv6#4 (text+ko) ====
@@ -24,7 +24,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $FreeBSD: src/etc/rc.d/network_ipv6,v 1.33 2003/04/29 12:08:43 jwd Exp $
+# $FreeBSD: src/etc/rc.d/network_ipv6,v 1.34 2003/05/12 11:36:50 ume Exp $
# From: src/etc/rc.network6,v 1.29 2002/04/06 15:15:43
#
@@ -33,301 +33,11 @@
# KEYWORD: FreeBSD
. /etc/rc.subr
+. /etc/network.subr
name="network_ipv6"
rcvar=`set_rcvar ipv6`
start_cmd="network_ipv6_start"
-#required_files="/etc/rc.network6"
-
-hexdigit()
-{
- if [ $1 -lt 10 ]; then
- echo $1
- else
- case $1 in
- 10) echo a ;;
- 11) echo b ;;
- 12) echo c ;;
- 13) echo d ;;
- 14) echo e ;;
- 15) echo f ;;
- esac
- fi
-}
-
-hexprint()
-{
- val=$1
- str=''
-
- dig=`hexdigit $((${val} & 15))`
- str=${dig}${str}
- val=$((${val} >> 4))
- while [ ${val} -gt 0 ]; do
- dig=`hexdigit $((${val} & 15))`
- str=${dig}${str}
- val=$((${val} >> 4))
- done
-
- echo ${str}
-}
-
-network6_interface_setup()
-{
- interfaces=$*
- rtsol_interfaces=''
- case ${ipv6_gateway_enable} in
- [Yy][Ee][Ss])
- rtsol_available=no
- ;;
- *)
- rtsol_available=yes
- ;;
- esac
- for i in $interfaces; do
- rtsol_interface=yes
- eval prefix=\$ipv6_prefix_$i
- if [ -n "${prefix}" ]; then
- rtsol_available=no
- rtsol_interface=no
- laddr=`network6_getladdr $i`
- hostid=`expr "${laddr}" : 'fe80::\(.*\)%\(.*\)'`
- for j in ${prefix}; do
- address=$j\:${hostid}
- ifconfig $i inet6 ${address} prefixlen 64 alias
-
- case ${ipv6_gateway_enable} in
- [Yy][Ee][Ss])
- # subnet-router anycast address
- # (rfc2373)
- ifconfig $i inet6 $j:: prefixlen 64 \
- alias anycast
- ;;
- esac
- done
- fi
- eval ipv6_ifconfig=\$ipv6_ifconfig_$i
- if [ -n "${ipv6_ifconfig}" ]; then
- rtsol_available=no
- rtsol_interface=no
- ifconfig $i inet6 ${ipv6_ifconfig} alias
- fi
-
- if [ ${rtsol_available} = yes -a ${rtsol_interface} = yes ]
- then
- case ${i} in
- lo0|gif[0-9]*|stf[0-9]*|faith[0-9]*|lp[0-9]*|sl[0-9]*|tun[0-9]*)
- ;;
- *)
- rtsol_interfaces="${rtsol_interfaces} ${i}"
- ;;
- esac
- else
- ifconfig $i inet6
- fi
- done
-
- if [ ${rtsol_available} = yes -a -n "${rtsol_interfaces}" ]; then
- # Act as endhost - automatically configured.
- # You can configure only single interface, as
- # specification assumes that autoconfigured host has
- # single interface only.
- sysctl net.inet6.ip6.accept_rtadv=1
- set ${rtsol_interfaces}
- ifconfig $1 up
- rtsol $1
- fi
-
- for i in $interfaces; do
- alias=0
- while : ; do
- eval ipv6_ifconfig=\$ipv6_ifconfig_${i}_alias${alias}
- if [ -z "${ipv6_ifconfig}" ]; then
- break;
- fi
- ifconfig $i inet6 ${ipv6_ifconfig} alias
- alias=$((${alias} + 1))
- done
- done
-}
-
-network6_stf_setup()
-{
- case ${stf_interface_ipv4addr} in
- [Nn][Oo] | '')
- ;;
- *)
- # assign IPv6 addr and interface route for 6to4 interface
- stf_prefixlen=$((16+${stf_interface_ipv4plen:-0}))
- OIFS="$IFS"
- IFS=".$IFS"
- set ${stf_interface_ipv4addr}
- IFS="$OIFS"
- hexfrag1=`hexprint $(($1*256 + $2))`
- hexfrag2=`hexprint $(($3*256 + $4))`
- ipv4_in_hexformat="${hexfrag1}:${hexfrag2}"
- case ${stf_interface_ipv6_ifid} in
- [Aa][Uu][Tt][Oo] | '')
- for i in ${ipv6_network_interfaces}; do
- laddr=`network6_getladdr ${i}`
- case ${laddr} in
- '')
- ;;
- *)
- break
- ;;
- esac
- done
- stf_interface_ipv6_ifid=`expr "${laddr}" : \
- 'fe80::\(.*\)%\(.*\)'`
- case ${stf_interface_ipv6_ifid} in
- '')
- stf_interface_ipv6_ifid=0:0:0:1
- ;;
- esac
- ;;
- esac
- ifconfig stf0 create >/dev/null 2>&1
- ifconfig stf0 inet6 2002:${ipv4_in_hexformat}:${stf_interface_ipv6_slaid:-0}:${stf_interface_ipv6_ifid} \
- prefixlen ${stf_prefixlen}
- # disallow packets to malicious 6to4 prefix
- route add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
- route add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
- route add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
- route add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
- ;;
- esac
-}
-
-network6_static_routes_setup()
-{
- # Set up any static routes.
- case ${ipv6_defaultrouter} in
- [Nn][Oo] | '')
- ;;
- *)
- ipv6_static_routes="default ${ipv6_static_routes}"
- ipv6_route_default="default ${ipv6_defaultrouter}"
- ;;
- esac
- case ${ipv6_static_routes} in
- [Nn][Oo] | '')
- ;;
- *)
- for i in ${ipv6_static_routes}; do
- eval ipv6_route_args=\$ipv6_route_${i}
- route add -inet6 ${ipv6_route_args}
- done
- ;;
- esac
-}
-
-network6_faith_setup()
-{
- case ${ipv6_faith_prefix} in
- [Nn][Oo] | '')
- ;;
- *)
- sysctl net.inet6.ip6.keepfaith=1
- ifconfig faith0 create >/dev/null 2>&1
- ifconfig faith0 up
- for prefix in ${ipv6_faith_prefix}; do
- prefixlen=`expr "${prefix}" : ".*/\(.*\)"`
- case ${prefixlen} in
- '')
- prefixlen=96
- ;;
- *)
- prefix=`expr "${prefix}" : \
- "\(.*\)/${prefixlen}"`
- ;;
- esac
- route add -inet6 ${prefix} -prefixlen ${prefixlen} ::1
- route change -inet6 ${prefix} -prefixlen ${prefixlen} \
- -ifp faith0
- done
- ;;
- esac
-}
-
-network6_default_interface_setup()
-{
- # Choose IPv6 default interface if it is not clearly specified.
- case ${ipv6_default_interface} in
- '')
- for i in ${ipv6_network_interfaces}; do
- case $i in
- lo0|faith[0-9]*)
- continue
- ;;
- esac
- laddr=`network6_getladdr $i exclude_tentative`
- case ${laddr} in
- '')
- ;;
- *)
- ipv6_default_interface=$i
- break
- ;;
- esac
- done
- ;;
- esac
-
- # Disallow unicast packets without outgoing scope identifiers,
- # or route such packets to a "default" interface, if it is specified.
- route add -inet6 fe80:: -prefixlen 10 ::1 -reject
- case ${ipv6_default_interface} in
- [Nn][Oo] | '')
- route add -inet6 ff02:: -prefixlen 16 ::1 -reject
- ;;
- *)
- laddr=`network6_getladdr ${ipv6_default_interface}`
- route add -inet6 ff02:: ${laddr} -prefixlen 16 -interface \
- -cloning
-
- # Disable installing the default interface with the
- # case net.inet6.ip6.forwarding=0 and
- # net.inet6.ip6.accept_rtadv=0, due to avoid conflict
- # between the default router list and the manual
- # configured default route.
- case ${ipv6_gateway_enable} in
- [Yy][Ee][Ss])
- ;;
- *)
- if [ `sysctl -n net.inet6.ip6.accept_rtadv` -eq 1 ]
- then
- ndp -I ${ipv6_default_interface}
- fi
- ;;
- esac
- ;;
- esac
-}
-
-network6_getladdr()
-{
- ifconfig $1 2>/dev/null | while read proto addr rest; do
- case ${proto} in
- inet6)
- case ${addr} in
- fe80::*)
- if [ -z "$2" ]; then
- echo ${addr}
- return
- fi
- case ${rest} in
- *tentative*)
- continue
- ;;
- *)
- echo ${addr}
- return
- esac
- esac
- esac
- done
-}
network_ipv6_start()
{
==== //depot/projects/hammer/lib/libthr/thread/thr_kern.c#3 (text+ko) ====
@@ -23,7 +23,7 @@
* (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: src/lib/libthr/thread/thr_kern.c,v 1.3 2003/04/20 02:58:30 marcel Exp $
+ * $FreeBSD: src/lib/libthr/thread/thr_kern.c,v 1.5 2003/05/12 10:48:02 mtm Exp $
*/
#include <sys/cdefs.h>
@@ -52,6 +52,56 @@
static sigset_t restore;
void
+_thread_critical_enter(pthread_t pthread)
+{
+ sigset_t set;
+ sigset_t sav;
+
+ /*
+ * Block all signals.
+ */
+ SIGFILLSET(set);
+
+ /*
+ * We can not use the global 'restore' set until after we have
+ * acquired the giant lock.
+ */
+ _SPINLOCK(&pthread->lock);
+ if (__sys_sigprocmask(SIG_SETMASK, &set, &sav)) {
+ _thread_printf(STDERR_FILENO, "Critical Enter: sig err %d\n",
+ errno);
+ abort();
+ }
+
+ restore = sav;
+}
+
+void
+_thread_critical_exit(pthread_t pthread)
+{
+ sigset_t set;
+ int error;
+
+ /*
+ * restore is protected by giant. We could restore our signal state
+ * incorrectly if someone else set restore between unlocking giant
+ * and restoring the signal mask. To avoid this we cache a copy prior
+ * to the unlock.
+ */
+ set = restore;
+
+ /*
+ * Restore signals.
+ */
+ if (__sys_sigprocmask(SIG_SETMASK, &set, NULL)) {
+ _thread_printf(STDERR_FILENO, "Critical Exit: sig err %d\n",
+ errno);
+ abort();
+ }
+ _SPINUNLOCK(&pthread->lock);
+}
+
+void
GIANT_LOCK(pthread_t pthread)
{
sigset_t set;
==== //depot/projects/hammer/lib/libthr/thread/thr_mutex.c#3 (text+ko) ====
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libthr/thread/thr_mutex.c,v 1.4 2003/05/06 02:30:52 mtm Exp $
+ * $FreeBSD: src/lib/libthr/thread/thr_mutex.c,v 1.6 2003/05/12 10:48:02 mtm Exp $
*/
#include <stdlib.h>
#include <errno.h>
@@ -62,6 +62,8 @@
/*
* Prototypes
*/
+static int get_muncontested(pthread_mutex_t, int);
+static void get_mcontested(pthread_mutex_t);
static inline int mutex_self_trylock(pthread_mutex_t);
static inline int mutex_self_lock(pthread_mutex_t);
static inline int mutex_unlock_common(pthread_mutex_t *, int);
@@ -297,138 +299,6 @@
return (ret);
}
-static int
-mutex_trylock_common(pthread_mutex_t *mutex)
-{
- int ret = 0;
-
- PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL),
- "Uninitialized mutex in pthread_mutex_trylock_basic");
-
- /*
- * Defer signals to protect the scheduling queues from
- * access by the signal handler:
- */
- /* _thread_kern_sig_defer(); XXXThr */
-
- /* Lock the mutex structure: */
- _SPINLOCK(&(*mutex)->lock);
-
- /*
- * If the mutex was statically allocated, properly
- * initialize the tail queue.
- */
- if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) {
- TAILQ_INIT(&(*mutex)->m_queue);
- _MUTEX_INIT_LINK(*mutex);
- (*mutex)->m_flags |= MUTEX_FLAGS_INITED;
- }
-
- /* Process according to mutex type: */
- switch ((*mutex)->m_protocol) {
- /* Default POSIX mutex: */
- case PTHREAD_PRIO_NONE:
- /* Check if this mutex is not locked: */
- if ((*mutex)->m_owner == NULL) {
- /* Lock the mutex for the running thread: */
- (*mutex)->m_owner = curthread;
-
- /* Add to the list of owned mutexes: */
- _MUTEX_ASSERT_NOT_OWNED(*mutex);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*mutex), m_qe);
- } else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_trylock(*mutex);
- else
- /* Return a busy error: */
- ret = EBUSY;
- break;
-
- /* POSIX priority inheritence mutex: */
- case PTHREAD_PRIO_INHERIT:
- /* Check if this mutex is not locked: */
- if ((*mutex)->m_owner == NULL) {
- /* Lock the mutex for the running thread: */
- (*mutex)->m_owner = curthread;
-
- /* Track number of priority mutexes owned: */
- curthread->priority_mutex_count++;
-
- /*
- * The mutex takes on the attributes of the
- * running thread when there are no waiters.
- */
- (*mutex)->m_prio = curthread->active_priority;
- (*mutex)->m_saved_prio =
- curthread->inherited_priority;
-
- /* Add to the list of owned mutexes: */
- _MUTEX_ASSERT_NOT_OWNED(*mutex);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*mutex), m_qe);
- } else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_trylock(*mutex);
- else
- /* Return a busy error: */
- ret = EBUSY;
- break;
-
- /* POSIX priority protection mutex: */
- case PTHREAD_PRIO_PROTECT:
- /* Check for a priority ceiling violation: */
- if (curthread->active_priority > (*mutex)->m_prio)
- ret = EINVAL;
-
- /* Check if this mutex is not locked: */
- else if ((*mutex)->m_owner == NULL) {
- /* Lock the mutex for the running thread: */
- (*mutex)->m_owner = curthread;
-
- /* Track number of priority mutexes owned: */
- curthread->priority_mutex_count++;
-
- /*
- * The running thread inherits the ceiling
- * priority of the mutex and executes at that
- * priority.
- */
- curthread->active_priority = (*mutex)->m_prio;
- (*mutex)->m_saved_prio =
- curthread->inherited_priority;
- curthread->inherited_priority =
- (*mutex)->m_prio;
-
- /* Add to the list of owned mutexes: */
- _MUTEX_ASSERT_NOT_OWNED(*mutex);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*mutex), m_qe);
- } else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_trylock(*mutex);
- else
- /* Return a busy error: */
- ret = EBUSY;
- break;
-
- /* Trap invalid mutex types: */
- default:
- /* Return an invalid argument error: */
- ret = EINVAL;
- break;
- }
-
- /* Unlock the mutex structure: */
- _SPINUNLOCK(&(*mutex)->lock);
-
- /*
- * Undefer and handle pending signals, yielding if
- * necessary:
- */
- /* _thread_kern_sig_undefer(); */
-
- /* Return the completion status: */
- return (ret);
-}
-
int
__pthread_mutex_trylock(pthread_mutex_t *mutex)
{
@@ -442,7 +312,7 @@
* initialization:
*/
else if ((*mutex != NULL) || (ret = init_static(mutex)) == 0)
- ret = mutex_trylock_common(mutex);
+ ret = mutex_lock_common(mutex, 1);
return (ret);
}
@@ -460,15 +330,17 @@
* initialization marking the mutex private (delete safe):
*/
else if ((*mutex != NULL) || (ret = init_static_private(mutex)) == 0)
- ret = mutex_trylock_common(mutex);
+ ret = mutex_lock_common(mutex, 1);
return (ret);
}
static int
-mutex_lock_common(pthread_mutex_t * mutex)
+mutex_lock_common(pthread_mutex_t * mutex, int nonblock)
{
- int ret = 0;
+ int ret, error, inCancel;
+
+ ret = error = inCancel = 0;
PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL),
"Uninitialized mutex in mutex_lock_common");
@@ -505,51 +377,20 @@
switch ((*mutex)->m_protocol) {
/* Default POSIX mutex: */
case PTHREAD_PRIO_NONE:
- if ((*mutex)->m_owner == NULL) {
- /* Lock the mutex for this thread: */
- (*mutex)->m_owner = curthread;
-
- /* Add to the list of owned mutexes: */
- _MUTEX_ASSERT_NOT_OWNED(*mutex);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*mutex), m_qe);
-
- } else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_lock(*mutex);
- else {
- /*
- * Join the queue of threads waiting to lock
- * the mutex:
- */
- mutex_queue_enq(*mutex, curthread);
-
- /*
- * Keep a pointer to the mutex this thread
- * is waiting on:
- */
- curthread->data.mutex = *mutex;
-
- /*
- * Unlock the mutex structure and schedule the
- * next thread:
- */
- /* XXX Sched lock. */
- PTHREAD_SET_STATE(curthread, PS_MUTEX_WAIT);
- _SPINUNLOCK(&(*mutex)->lock);
- _thread_suspend(curthread, NULL);
-
- /* Lock the mutex structure again: */
- _SPINLOCK(&(*mutex)->lock);
- }
+ if ((error = get_muncontested(*mutex, nonblock)) == -1)
+ if (nonblock) {
+ ret = EBUSY;
+ break;
+ } else {
+ get_mcontested(*mutex);
+ }
+ else
+ ret = error;
break;
/* POSIX priority inheritence mutex: */
case PTHREAD_PRIO_INHERIT:
- /* Check if this mutex is not locked: */
- if ((*mutex)->m_owner == NULL) {
- /* Lock the mutex for this thread: */
- (*mutex)->m_owner = curthread;
-
+ if ((error = get_muncontested(*mutex, nonblock)) == 0) {
/* Track number of priority mutexes owned: */
curthread->priority_mutex_count++;
@@ -562,43 +403,20 @@
curthread->inherited_priority;
curthread->inherited_priority =
(*mutex)->m_prio;
-
- /* Add to the list of owned mutexes: */
- _MUTEX_ASSERT_NOT_OWNED(*mutex);
- TAILQ_INSERT_TAIL(&curthread->mutexq,
- (*mutex), m_qe);
-
- } else if ((*mutex)->m_owner == curthread)
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list