mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-17 03:49:46 +08:00
b359e82cea
Tom Fitzsimmons <fitzsim@redhat.com> * configure.in: Add iconvdata support for x86 linux. * configure: Regenerated. * libc/sys/linux/Makefile.am: Add EL/IX level 3 network, dynamic library, iconv, and linuxthreads support. * libc/sys/linux/configure.in: Ditto. * libc/sys/linux/Makefile.in: Regenerated. * libc/sys/linux/configure: Ditto. * iconvdata/EUC-JP.irreversible: New file. * iconvdata/Makefile.am: Ditto. * iconvdata/Makefile.in: Ditto. * iconvdata/SJIS.irreversible: Ditto. * iconvdata/aclocal.m4: Ditto. * iconvdata/configure: Ditto. * iconvdata/configure.in: Ditto. * iconvdata/dummy.c: Ditto. * iconvdata/euc-jp.c: Ditto. * iconvdata/gconv-modules: Ditto. * iconvdata/jis0201.c: Ditto. * iconvdata/jis0201.h: Ditto. * iconvdata/jis0208.c: Ditto. * iconvdata/jis0208.h: Ditto. * iconvdata/jis0212.c: Ditto. * iconvdata/jis0212.h: Ditto. * iconvdata/sjis.c: Ditto. * libc/include/errno.h: Protect definition of error_t. * libc/sys/linux/gethostid.c: New file. * libc/sys/linux/sethostid.c: Ditto. * libc/sys/linux/dl/Makefile.am: Ditto. * libc/sys/linux/dl/Makefile.in: Ditto. * libc/sys/linux/dl/abi-tag.h: Ditto. * libc/sys/linux/dl/atomicity.h: Ditto. * libc/sys/linux/dl/dl-addr.c: Ditto. * libc/sys/linux/dl/dl-cache.c: Ditto. * libc/sys/linux/dl/dl-cache.h: Ditto. * libc/sys/linux/dl/dl-close.c: Ditto. * libc/sys/linux/dl/dl-debug.c: Ditto. * libc/sys/linux/dl/dl-deps.c: Ditto. * libc/sys/linux/dl/dl-dst.h: Ditto. * libc/sys/linux/dl/dl-error.c: Ditto. * libc/sys/linux/dl/dl-fini.c: Ditto. * libc/sys/linux/dl/dl-init.c: Ditto. * libc/sys/linux/dl/dl-iteratephdr.c: Ditto. * libc/sys/linux/dl/dl-libc.c: Ditto. * libc/sys/linux/dl/dl-librecon.h: Ditto. * libc/sys/linux/dl/dl-load.c: Ditto. * libc/sys/linux/dl/dl-lookup.c: Ditto. * libc/sys/linux/dl/dl-lookupcfg.h: Ditto. * libc/sys/linux/dl/dl-minimal.c: Ditto. * libc/sys/linux/dl/dl-misc.c: Ditto. * libc/sys/linux/dl/dl-object.c: Ditto. * libc/sys/linux/dl/dl-open.c: Ditto. * libc/sys/linux/dl/dl-osinfo.h: Ditto. * libc/sys/linux/dl/dl-profile.c: Ditto. * libc/sys/linux/dl/dl-profstub.c: Ditto. * libc/sys/linux/dl/dl-reloc.c: Ditto. * libc/sys/linux/dl/dl-runtime.c: Ditto. * libc/sys/linux/dl/dl-support.c: Ditto. * libc/sys/linux/dl/dl-sym.c: Ditto. * libc/sys/linux/dl/dl-version.c: Ditto. * libc/sys/linux/dl/dlfcn.h: Ditto. * libc/sys/linux/dl/do-lookup.h: Ditto. * libc/sys/linux/dl/do-rel.h: Ditto. * libc/sys/linux/dl/dynamic-link.h: Ditto. * libc/sys/linux/dl/kernel-features.h: Ditto. * libc/sys/linux/dl/ldsodefs.h: Ditto. * libc/sys/linux/dl/libintl.h: Ditto. * libc/sys/linux/dl/trusted-dirs.h: Ditto. * libc/sys/linux/dl/unsecvars.h: Ditto. * libc/sys/linux/iconv/Makefile.am: Ditto. * libc/sys/linux/iconv/Makefile.in: Ditto. * libc/sys/linux/iconv/categories.def: Ditto. * libc/sys/linux/iconv/dummy-repertoire.c: Ditto. * libc/sys/linux/iconv/gconv.c: Ditto. * libc/sys/linux/iconv/gconv_builtin.c: Ditto. * libc/sys/linux/iconv/gconv_builtin.h: Ditto. * libc/sys/linux/iconv/gconv_cache.c: Ditto. * libc/sys/linux/iconv/gconv_charset.h: Ditto. * libc/sys/linux/iconv/gconv_close.c: Ditto. * libc/sys/linux/iconv/gconv_conf.c: Ditto. * libc/sys/linux/iconv/gconv_db.c: Ditto. * libc/sys/linux/iconv/gconv_dl.c: Ditto. * libc/sys/linux/iconv/gconv_int.h: Ditto. * libc/sys/linux/iconv/gconv_open.c: Ditto. * libc/sys/linux/iconv/gconv_simple.c: Ditto. * libc/sys/linux/iconv/gconv_trans.c: Ditto. * libc/sys/linux/iconv/hash-string.h: Ditto. * libc/sys/linux/iconv/iconv.c: Ditto. * libc/sys/linux/iconv/iconv.h: Ditto. * libc/sys/linux/iconv/iconv_charmap.c: Ditto. * libc/sys/linux/iconv/iconv_close.c: Ditto. * libc/sys/linux/iconv/iconv_open.c: Ditto. * libc/sys/linux/iconv/iconvconfig.c: Ditto. * libc/sys/linux/iconv/iconvconfig.h: Ditto. * libc/sys/linux/iconv/loadinfo.h: Ditto. * libc/sys/linux/iconv/localeinfo.h: Ditto. * libc/sys/linux/iconv/loop.c: Ditto. * libc/sys/linux/iconv/skeleton.c: Ditto. * libc/sys/linux/iconv/strtab.c: Ditto. * libc/sys/linux/include/dl-hash.h: Ditto. * libc/sys/linux/include/dlfcn.h: Ditto. * libc/sys/linux/include/fnmatch.h: Ditto. * libc/sys/linux/include/gconv.h: Ditto. * libc/sys/linux/include/glob.h: Ditto. * libc/sys/linux/include/hesiod.h: Ditto. * libc/sys/linux/include/ifaddrs.h: Ditto. * libc/sys/linux/include/libc_private.h: Ditto. * libc/sys/linux/include/link.h: Ditto. * libc/sys/linux/include/namespace.h: Ditto. * libc/sys/linux/include/netconfig.h: Ditto. * libc/sys/linux/include/netdb.h: Ditto. * libc/sys/linux/include/nsswitch.h: Ditto. * libc/sys/linux/include/regex.h: Ditto. * libc/sys/linux/include/resolv.h: Ditto. * libc/sys/linux/include/rune.h: Ditto. * libc/sys/linux/include/runetype.h: Ditto. * libc/sys/linux/include/semaphore.h: Ditto. * libc/sys/linux/include/setlocale.h: Ditto. * libc/sys/linux/include/un-namespace.h: Ditto. * libc/sys/linux/include/wordexp.h: Ditto. * libc/sys/linux/include/arpa/ftp.h: Ditto. * libc/sys/linux/include/arpa/inet.h: Ditto. * libc/sys/linux/include/arpa/nameser.h: Ditto. * libc/sys/linux/include/arpa/nameser_compat.h: Ditto. * libc/sys/linux/include/arpa/telnet.h: Ditto. * libc/sys/linux/include/arpa/tftp.h: Ditto. * libc/sys/linux/include/net/bpf.h: Ditto. * libc/sys/linux/include/net/bpf_compat.h: Ditto. * libc/sys/linux/include/net/bpfdesc.h: Ditto. * libc/sys/linux/include/net/bridge.h: Ditto. * libc/sys/linux/include/net/ethernet.h: Ditto. * libc/sys/linux/include/net/fddi.h: Ditto. * libc/sys/linux/include/net/if.h: Ditto. * libc/sys/linux/include/net/if_arc.h: Ditto. * libc/sys/linux/include/net/if_arp.h: Ditto. * libc/sys/linux/include/net/if_atm.h: Ditto. * libc/sys/linux/include/net/if_dl.h: Ditto. * libc/sys/linux/include/net/if_gif.h: Ditto. * libc/sys/linux/include/net/if_ieee80211.h: Ditto. * libc/sys/linux/include/net/if_llc.h: Ditto. * libc/sys/linux/include/net/if_media.h: Ditto. * libc/sys/linux/include/net/if_mib.h: Ditto. * libc/sys/linux/include/net/if_ppp.h: Ditto. * libc/sys/linux/include/net/if_pppvar.h: Ditto. * libc/sys/linux/include/net/if_slvar.h: Ditto. * libc/sys/linux/include/net/if_sppp.h: Ditto. * libc/sys/linux/include/net/if_stf.h: Ditto. * libc/sys/linux/include/net/if_tap.h: Ditto. * libc/sys/linux/include/net/if_tapvar.h: Ditto. * libc/sys/linux/include/net/if_tun.h: Ditto. * libc/sys/linux/include/net/if_tunvar.h: Ditto. * libc/sys/linux/include/net/if_types.h: Ditto. * libc/sys/linux/include/net/if_var.h: Ditto. * libc/sys/linux/include/net/if_vlan_var.h: Ditto. * libc/sys/linux/include/net/intrq.h: Ditto. * libc/sys/linux/include/net/iso88025.h: Ditto. * libc/sys/linux/include/net/net_osdep.h: Ditto. * libc/sys/linux/include/net/netisr.h: Ditto. * libc/sys/linux/include/net/pfil.h: Ditto. * libc/sys/linux/include/net/pfkeyv2.h: Ditto. * libc/sys/linux/include/net/ppp_comp.h: Ditto. * libc/sys/linux/include/net/ppp_defs.h: Ditto. * libc/sys/linux/include/net/radix.h: Ditto. * libc/sys/linux/include/net/raw_cb.h: Ditto. * libc/sys/linux/include/net/route.h: Ditto. * libc/sys/linux/include/net/slcompress.h: Ditto. * libc/sys/linux/include/net/slip.h: Ditto. * libc/sys/linux/include/net/zlib.h: Ditto. * libc/sys/linux/include/netinet/icmp6.h: Ditto. * libc/sys/linux/include/netinet/icmp_var.h: Ditto. * libc/sys/linux/include/netinet/if_atm.h: Ditto. * libc/sys/linux/include/netinet/if_ether.h: Ditto. * libc/sys/linux/include/netinet/igmp.h: Ditto. * libc/sys/linux/include/netinet/igmp_var.h: Ditto. * libc/sys/linux/include/netinet/in.h: Ditto. * libc/sys/linux/include/netinet/in_gif.h: Ditto. * libc/sys/linux/include/netinet/in_pcb.h: Ditto. * libc/sys/linux/include/netinet/in_systm.h: Ditto. * libc/sys/linux/include/netinet/in_var.h: Ditto. * libc/sys/linux/include/netinet/ip.h: Ditto. * libc/sys/linux/include/netinet/ip6.h: Ditto. * libc/sys/linux/include/netinet/ip_dummynet.h: Ditto. * libc/sys/linux/include/netinet/ip_ecn.h: Ditto. * libc/sys/linux/include/netinet/ip_encap.h: Ditto. * libc/sys/linux/include/netinet/ip_flow.h: Ditto. * libc/sys/linux/include/netinet/ip_fw.h: Ditto. * libc/sys/linux/include/netinet/ip_icmp.h: Ditto. * libc/sys/linux/include/netinet/ip_mroute.h: Ditto. * libc/sys/linux/include/netinet/ip_var.h: Ditto. * libc/sys/linux/include/netinet/ipprotosw.h: Ditto. * libc/sys/linux/include/netinet/tcp.h: Ditto. * libc/sys/linux/include/netinet/tcp_debug.h: Ditto. * libc/sys/linux/include/netinet/tcp_fsm.h: Ditto. * libc/sys/linux/include/netinet/tcp_seq.h: Ditto. * libc/sys/linux/include/netinet/tcp_timer.h: Ditto. * libc/sys/linux/include/netinet/tcp_var.h: Ditto. * libc/sys/linux/include/netinet/tcpip.h: Ditto. * libc/sys/linux/include/netinet/udp.h: Ditto. * libc/sys/linux/include/netinet/udp_var.h: Ditto. * libc/sys/linux/include/netinet6/ah.h: Ditto. * libc/sys/linux/include/netinet6/ah6.h: Ditto. * libc/sys/linux/include/netinet6/esp.h: Ditto. * libc/sys/linux/include/netinet6/esp6.h: Ditto. * libc/sys/linux/include/netinet6/esp_rijndael.h: Ditto. * libc/sys/linux/include/netinet6/icmp6.h: Ditto. * libc/sys/linux/include/netinet6/in6.h: Ditto. * libc/sys/linux/include/netinet6/in6_gif.h: Ditto. * libc/sys/linux/include/netinet6/in6_ifattach.h: Ditto. * libc/sys/linux/include/netinet6/in6_pcb.h: Ditto. * libc/sys/linux/include/netinet6/in6_prefix.h: Ditto. * libc/sys/linux/include/netinet6/in6_var.h: Ditto. * libc/sys/linux/include/netinet6/ip6.h: Ditto. * libc/sys/linux/include/netinet6/ip6_ecn.h: Ditto. * libc/sys/linux/include/netinet6/ip6_fw.h: Ditto. * libc/sys/linux/include/netinet6/ip6_mroute.h: Ditto. * libc/sys/linux/include/netinet6/ip6_var.h: Ditto. * libc/sys/linux/include/netinet6/ip6protosw.h: Ditto. * libc/sys/linux/include/netinet6/ipcomp.h: Ditto. * libc/sys/linux/include/netinet6/ipcomp6.h: Ditto. * libc/sys/linux/include/netinet6/ipsec.h: Ditto. * libc/sys/linux/include/netinet6/ipsec6.h: Ditto. * libc/sys/linux/include/netinet6/mld6_var.h: Ditto. * libc/sys/linux/include/netinet6/nd6.h: Ditto. * libc/sys/linux/include/netinet6/pim6.h: Ditto. * libc/sys/linux/include/netinet6/pim6_var.h: Ditto. * libc/sys/linux/include/netinet6/raw_ip6.h: Ditto. * libc/sys/linux/include/netinet6/scope6_var.h: Ditto. * libc/sys/linux/include/netinet6/tcp6_var.h: Ditto. * libc/sys/linux/include/netinet6/udp6_var.h: Ditto. * libc/sys/linux/include/netns/idp.h: Ditto. * libc/sys/linux/include/netns/idp_var.h: Ditto. * libc/sys/linux/include/netns/ns.h: Ditto. * libc/sys/linux/include/netns/ns_error.h: Ditto. * libc/sys/linux/include/netns/ns_if.h: Ditto. * libc/sys/linux/include/netns/ns_pcb.h: Ditto. * libc/sys/linux/include/netns/sp.h: Ditto. * libc/sys/linux/include/netns/spidp.h: Ditto. * libc/sys/linux/include/netns/spp_debug.h: Ditto. * libc/sys/linux/include/netns/spp_timer.h: Ditto. * libc/sys/linux/include/netns/spp_var.h: Ditto. * libc/sys/linux/include/rpc/Makefile: Ditto. * libc/sys/linux/include/rpc/auth.h: Ditto. * libc/sys/linux/include/rpc/auth_des.h: Ditto. * libc/sys/linux/include/rpc/auth_kerb.h: Ditto. * libc/sys/linux/include/rpc/auth_unix.h: Ditto. * libc/sys/linux/include/rpc/clnt.h: Ditto. * libc/sys/linux/include/rpc/clnt_soc.h: Ditto. * libc/sys/linux/include/rpc/clnt_stat.h: Ditto. * libc/sys/linux/include/rpc/des.h: Ditto. * libc/sys/linux/include/rpc/des_crypt.h: Ditto. * libc/sys/linux/include/rpc/nettype.h: Ditto. * libc/sys/linux/include/rpc/pmap_clnt.h: Ditto. * libc/sys/linux/include/rpc/pmap_prot.h: Ditto. * libc/sys/linux/include/rpc/pmap_rmt.h: Ditto. * libc/sys/linux/include/rpc/raw.h: Ditto. * libc/sys/linux/include/rpc/rpc.h: Ditto. * libc/sys/linux/include/rpc/rpc_com.h: Ditto. * libc/sys/linux/include/rpc/rpc_msg.h: Ditto. * libc/sys/linux/include/rpc/rpcb_clnt.h: Ditto. * libc/sys/linux/include/rpc/rpcb_prot.h: Ditto. * libc/sys/linux/include/rpc/rpcb_prot.x: Ditto. * libc/sys/linux/include/rpc/rpcent.h: Ditto. * libc/sys/linux/include/rpc/svc.h: Ditto. * libc/sys/linux/include/rpc/svc_auth.h: Ditto. * libc/sys/linux/include/rpc/svc_dg.h: Ditto. * libc/sys/linux/include/rpc/svc_soc.h: Ditto. * libc/sys/linux/include/rpc/types.h: Ditto. * libc/sys/linux/include/rpc/xdr.h: Ditto. * libc/sys/linux/intl/Makefile.am: Ditto. * libc/sys/linux/intl/Makefile.in: Ditto. * libc/sys/linux/intl/bindtextdom.c: Ditto. * libc/sys/linux/intl/catgets.c: Ditto. * libc/sys/linux/intl/catgetsinfo.h: Ditto. * libc/sys/linux/intl/config.h: Ditto. * libc/sys/linux/intl/dcgettext.c: Ditto. * libc/sys/linux/intl/dcigettext.c: Ditto. * libc/sys/linux/intl/dcngettext.c: Ditto. * libc/sys/linux/intl/dgettext.c: Ditto. * libc/sys/linux/intl/dngettext.c: Ditto. * libc/sys/linux/intl/explodename.c: Ditto. * libc/sys/linux/intl/finddomain.c: Ditto. * libc/sys/linux/intl/gettext.c: Ditto. * libc/sys/linux/intl/gettext.h: Ditto. * libc/sys/linux/intl/gettextP.h: Ditto. * libc/sys/linux/intl/hash-string.h: Ditto. * libc/sys/linux/intl/l10nflist.c: Ditto. * libc/sys/linux/intl/loadinfo.h: Ditto. * libc/sys/linux/intl/loadmsgcat.c: Ditto. * libc/sys/linux/intl/locale.alias: Ditto. * libc/sys/linux/intl/localealias.c: Ditto. * libc/sys/linux/intl/ngettext.c: Ditto. * libc/sys/linux/intl/open_catalog.c: Ditto. * libc/sys/linux/intl/plural.c: Ditto. * libc/sys/linux/intl/plural.y: Ditto. * libc/sys/linux/intl/stpcpy.c: Ditto. * libc/sys/linux/intl/textdomain.c: Ditto. * libc/sys/linux/linuxthreads/LICENSE: Ditto. * libc/sys/linux/linuxthreads/Makefile.am: Ditto. * libc/sys/linux/linuxthreads/Makefile.in: Ditto. * libc/sys/linux/linuxthreads/aclocal.m4: Ditto. * libc/sys/linux/linuxthreads/attr.c: Ditto. * libc/sys/linux/linuxthreads/barrier.c: Ditto. * libc/sys/linux/linuxthreads/bp-sym.h: Ditto. * libc/sys/linux/linuxthreads/cancel.c: Ditto. * libc/sys/linux/linuxthreads/condvar.c: Ditto. * libc/sys/linux/linuxthreads/config.h: Ditto. * libc/sys/linux/linuxthreads/configure: Ditto. * libc/sys/linux/linuxthreads/configure.in: Ditto. * libc/sys/linux/linuxthreads/defs.awk: Ditto. * libc/sys/linux/linuxthreads/ecmutex.c: Ditto. * libc/sys/linux/linuxthreads/events.c: Ditto. * libc/sys/linux/linuxthreads/getcpuclockid.c: Ditto. * libc/sys/linux/linuxthreads/getreent.c: Ditto. * libc/sys/linux/linuxthreads/internals.h: Ditto. * libc/sys/linux/linuxthreads/join.c: Ditto. * libc/sys/linux/linuxthreads/joinrace.c: Ditto. * libc/sys/linux/linuxthreads/kernel-features.h: Ditto. * libc/sys/linux/linuxthreads/libc-internal.h: Ditto. * libc/sys/linux/linuxthreads/libc-symbols.h: Ditto. * libc/sys/linux/linuxthreads/linuxthreads.texi: Ditto. * libc/sys/linux/linuxthreads/lockfile.c: Ditto. * libc/sys/linux/linuxthreads/manager.c: Ditto. * libc/sys/linux/linuxthreads/mq_notify.c: Ditto. * libc/sys/linux/linuxthreads/mutex.c: Ditto. * libc/sys/linux/linuxthreads/no-tsd.c: Ditto. * libc/sys/linux/linuxthreads/oldsemaphore.c: Ditto. * libc/sys/linux/linuxthreads/posix-timer.h: Ditto. * libc/sys/linux/linuxthreads/prio.c: Ditto. * libc/sys/linux/linuxthreads/proc_service.h: Ditto. * libc/sys/linux/linuxthreads/pt-machine.c: Ditto. * libc/sys/linux/linuxthreads/ptclock_gettime.c: Ditto. * libc/sys/linux/linuxthreads/ptclock_settime.c: Ditto. * libc/sys/linux/linuxthreads/ptfork.c: Ditto. * libc/sys/linux/linuxthreads/pthread.c: Ditto. * libc/sys/linux/linuxthreads/ptlongjmp.c: Ditto. * libc/sys/linux/linuxthreads/queue.h: Ditto. * libc/sys/linux/linuxthreads/reent.c: Ditto. * libc/sys/linux/linuxthreads/reqsyscalls.c: Ditto. * libc/sys/linux/linuxthreads/restart.h: Ditto. * libc/sys/linux/linuxthreads/rwlock.c: Ditto. * libc/sys/linux/linuxthreads/semaphore.c: Ditto. * libc/sys/linux/linuxthreads/semaphore.h: Ditto. * libc/sys/linux/linuxthreads/shlib-compat.h: Ditto. * libc/sys/linux/linuxthreads/signals.c: Ditto. * libc/sys/linux/linuxthreads/specific.c: Ditto. * libc/sys/linux/linuxthreads/spinlock.c: Ditto. * libc/sys/linux/linuxthreads/spinlock.h: Ditto. * libc/sys/linux/linuxthreads/sysctl.c: Ditto. * libc/sys/linux/linuxthreads/td_init.c: Ditto. * libc/sys/linux/linuxthreads/td_log.c: Ditto. * libc/sys/linux/linuxthreads/td_symbol_list.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_clear_event.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_delete.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_enable_stats.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_event_addr.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_event_getmsg.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_get_nthreads.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_get_ph.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_get_stats.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_map_id2thr.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_map_lwp2thr.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_new.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_reset_stats.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_set_event.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_setconcurrency.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_thr_iter.c: Ditto. * libc/sys/linux/linuxthreads/td_ta_tsd_iter.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_clear_event.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_dbresume.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_dbsuspend.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_event_enable.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_event_getmsg.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_get_info.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_getfpregs.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_getgregs.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_getxregs.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_getxregsize.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_set_event.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_setfpregs.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_setgregs.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_setprio.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_setsigpending.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_setxregs.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_sigsetmask.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_tsd.c: Ditto. * libc/sys/linux/linuxthreads/td_thr_validate.c: Ditto. * libc/sys/linux/linuxthreads/testrtsig.h: Ditto. * libc/sys/linux/linuxthreads/thread_db.h: Ditto. * libc/sys/linux/linuxthreads/thread_dbP.h: Ditto. * libc/sys/linux/linuxthreads/timer_create.c: Ditto. * libc/sys/linux/linuxthreads/timer_delete.c: Ditto. * libc/sys/linux/linuxthreads/timer_getoverr.c: Ditto. * libc/sys/linux/linuxthreads/timer_gettime.c: Ditto. * libc/sys/linux/linuxthreads/timer_routines.c: Ditto. * libc/sys/linux/linuxthreads/timer_settime.c: Ditto. * libc/sys/linux/linuxthreads/tst-cancel.c: Ditto. * libc/sys/linux/linuxthreads/tst-context.c: Ditto. * libc/sys/linux/linuxthreads/tststack.c: Ditto. * libc/sys/linux/linuxthreads/unload.c: Ditto. * libc/sys/linux/linuxthreads/weaks.c: Ditto. * libc/sys/linux/linuxthreads/wrapsyscall.c: Ditto. * libc/sys/linux/linuxthreads/bits/initspin.h: Ditto. * libc/sys/linux/linuxthreads/bits/libc-lock.h: Ditto. * libc/sys/linux/linuxthreads/bits/libc-tsd.h: Ditto. * libc/sys/linux/linuxthreads/bits/local_lim.h: Ditto. * libc/sys/linux/linuxthreads/bits/posix_opt.h: Ditto. * libc/sys/linux/linuxthreads/bits/pthreadtypes.h: Ditto. * libc/sys/linux/linuxthreads/bits/sigthread.h: Ditto. * libc/sys/linux/linuxthreads/machine/Makefile.am: Ditto. * libc/sys/linux/linuxthreads/machine/Makefile.in: Ditto. * libc/sys/linux/linuxthreads/machine/aclocal.m4: Ditto. * libc/sys/linux/linuxthreads/machine/configure: Ditto. * libc/sys/linux/linuxthreads/machine/configure.in: Ditto. * libc/sys/linux/linuxthreads/machine/generic/generic-sysd: Ditto.ep.h * libc/sys/linux/linuxthreads/machine/i386/Makefile.am: Ditto. * libc/sys/linux/linuxthreads/machine/i386/Makefile.in: Ditto. * libc/sys/linux/linuxthreads/machine/i386/aclocal.m4: Ditto. * libc/sys/linux/linuxthreads/machine/i386/bp-asm.h: Ditto. * libc/sys/linux/linuxthreads/machine/i386/clone.S: Ditto. * libc/sys/linux/linuxthreads/machine/i386/configure: Ditto. * libc/sys/linux/linuxthreads/machine/i386/configure.in: Ditto. * libc/sys/linux/linuxthreads/machine/i386/i386-sysdep.S: Ditto. * libc/sys/linux/linuxthreads/machine/i386/i386-sysdep.h: Ditto. * libc/sys/linux/linuxthreads/machine/i386/pspinlock.c: Ditto. * libc/sys/linux/linuxthreads/machine/i386/pt-machine.h: Ditto. * libc/sys/linux/linuxthreads/machine/i386/sigcontextinfo.h: Ditto. * libc/sys/linux/linuxthreads/machine/i386/stackinfo.h: Ditto. * libc/sys/linux/linuxthreads/machine/i386/sysdep.S: Ditto. * libc/sys/linux/linuxthreads/machine/i386/sysdep.h: Ditto. * libc/sys/linux/linuxthreads/machine/i386/useldt.h: Ditto. * libc/sys/linux/machine/i386/dl-machine.h: Ditto. * libc/sys/linux/net/Makefile.am: Ditto. * libc/sys/linux/net/Makefile.in: Ditto. * libc/sys/linux/net/addr2ascii.3: Ditto. * libc/sys/linux/net/addr2ascii.c: Ditto. * libc/sys/linux/net/ascii2addr.c: Ditto. * libc/sys/linux/net/base64.c: Ditto. * libc/sys/linux/net/bindresvport.c: Ditto. * libc/sys/linux/net/byteorder.3: Ditto. * libc/sys/linux/net/ether_addr.c: Ditto. * libc/sys/linux/net/ethers.3: Ditto. * libc/sys/linux/net/getaddrinfo.3: Ditto. * libc/sys/linux/net/getaddrinfo.c: Ditto. * libc/sys/linux/net/gethostbydns.c: Ditto. * libc/sys/linux/net/gethostbyht.c: Ditto. * libc/sys/linux/net/gethostbyname.3: Ditto. * libc/sys/linux/net/gethostbynis.c: Ditto. * libc/sys/linux/net/gethostnamadr.c: Ditto. * libc/sys/linux/net/getifaddrs.3: Ditto. * libc/sys/linux/net/getifaddrs.c: Ditto. * libc/sys/linux/net/getipnodebyname.3: Ditto. * libc/sys/linux/net/getnameinfo.3: Ditto. * libc/sys/linux/net/getnameinfo.c: Ditto. * libc/sys/linux/net/getnetbydns.c: Ditto. * libc/sys/linux/net/getnetbyht.c: Ditto. * libc/sys/linux/net/getnetbynis.c: Ditto. * libc/sys/linux/net/getnetent.3: Ditto. * libc/sys/linux/net/getnetnamadr.c: Ditto. * libc/sys/linux/net/getproto.c: Ditto. * libc/sys/linux/net/getprotoent.3: Ditto. * libc/sys/linux/net/getprotoent.c: Ditto. * libc/sys/linux/net/getprotoname.c: Ditto. * libc/sys/linux/net/getservbyname.c: Ditto. * libc/sys/linux/net/getservbyport.c: Ditto. * libc/sys/linux/net/getservent.3: Ditto. * libc/sys/linux/net/getservent.c: Ditto. * libc/sys/linux/net/herror.c: Ditto. * libc/sys/linux/net/hesiod.3: Ditto. * libc/sys/linux/net/hesiod.c: Ditto. * libc/sys/linux/net/if_indextoname.3: Ditto. * libc/sys/linux/net/ifname.c: Ditto. * libc/sys/linux/net/inet.3: Ditto. * libc/sys/linux/net/inet6_option_s: Ditto.pace.3 * libc/sys/linux/net/inet6_rthdr_space.3: Ditto. * libc/sys/linux/net/inet_addr.c: Ditto. * libc/sys/linux/net/inet_lnaof.c: Ditto. * libc/sys/linux/net/inet_makeaddr.c: Ditto. * libc/sys/linux/net/inet_net.3: Ditto. * libc/sys/linux/net/inet_net_ntop.c: Ditto. * libc/sys/linux/net/inet_net_pton.c: Ditto. * libc/sys/linux/net/inet_neta.c: Ditto. * libc/sys/linux/net/inet_netof.c: Ditto. * libc/sys/linux/net/inet_network.c: Ditto. * libc/sys/linux/net/inet_ntoa.c: Ditto. * libc/sys/linux/net/inet_ntop.c: Ditto. * libc/sys/linux/net/inet_pton.c: Ditto. * libc/sys/linux/net/innetgr-stub.c: Ditto. * libc/sys/linux/net/ip6opt.c: Ditto. * libc/sys/linux/net/iso_addr.3: Ditto. * libc/sys/linux/net/iso_addr.c: Ditto. * libc/sys/linux/net/issetugid-stub.c: Ditto. * libc/sys/linux/net/linkaddr.3: Ditto. * libc/sys/linux/net/linkaddr.c: Ditto. * libc/sys/linux/net/map_v4v6.c: Ditto. * libc/sys/linux/net/name6.c: Ditto. * libc/sys/linux/net/namespace.h: Ditto. * libc/sys/linux/net/ns.3: Ditto. * libc/sys/linux/net/ns_addr.c: Ditto. * libc/sys/linux/net/ns_name.c: Ditto. * libc/sys/linux/net/ns_netint.c: Ditto. * libc/sys/linux/net/ns_ntoa.c: Ditto. * libc/sys/linux/net/ns_parse.c: Ditto. * libc/sys/linux/net/ns_print.c: Ditto. * libc/sys/linux/net/ns_ttl.c: Ditto. * libc/sys/linux/net/nsap_addr.c: Ditto. * libc/sys/linux/net/nsdispatch.3: Ditto. * libc/sys/linux/net/nsdispatch.c: Ditto. * libc/sys/linux/net/nslexer.c: Ditto. * libc/sys/linux/net/nslexer.l: Ditto. * libc/sys/linux/net/nsparser.c: Ditto. * libc/sys/linux/net/nsparser.h: Ditto. * libc/sys/linux/net/nsparser.y: Ditto. * libc/sys/linux/net/rcmd.3: Ditto. * libc/sys/linux/net/rcmd.c: Ditto. * libc/sys/linux/net/rcmdsh.3: Ditto. * libc/sys/linux/net/rcmdsh.c: Ditto. * libc/sys/linux/net/recv.c: Ditto. * libc/sys/linux/net/res_comp.c: Ditto. * libc/sys/linux/net/res_config.h: Ditto. * libc/sys/linux/net/res_data.c: Ditto. * libc/sys/linux/net/res_debug.c: Ditto. * libc/sys/linux/net/res_init.c: Ditto. * libc/sys/linux/net/res_mkquery.c: Ditto. * libc/sys/linux/net/res_mkupdate.c: Ditto. * libc/sys/linux/net/res_query.c: Ditto. * libc/sys/linux/net/res_send.c: Ditto. * libc/sys/linux/net/res_update.c: Ditto. * libc/sys/linux/net/resolver.3: Ditto. * libc/sys/linux/net/rthdr.c: Ditto. * libc/sys/linux/net/send.c: Ditto. * libc/sys/linux/net/un-namespace.h: Ditto. * libc/sys/linux/net/vars.c: Ditto. * libc/sys/linux/stdlib/COPYRIGHT: Ditto. * libc/sys/linux/stdlib/Makefile.am: Ditto. * libc/sys/linux/stdlib/Makefile.in: Ditto. * libc/sys/linux/stdlib/cclass.h: Ditto. * libc/sys/linux/stdlib/cname.h: Ditto. * libc/sys/linux/stdlib/collate.c: Ditto. * libc/sys/linux/stdlib/collate.h: Ditto. * libc/sys/linux/stdlib/collcmp.c: Ditto. * libc/sys/linux/stdlib/engine.c: Ditto. * libc/sys/linux/stdlib/fnmatch.3: Ditto. * libc/sys/linux/stdlib/fnmatch.c: Ditto. * libc/sys/linux/stdlib/glob.3: Ditto. * libc/sys/linux/stdlib/glob.c: Ditto. * libc/sys/linux/stdlib/reallocf.c: Ditto. * libc/sys/linux/stdlib/regcomp.c: Ditto. * libc/sys/linux/stdlib/regerror.c: Ditto. * libc/sys/linux/stdlib/regex.3: Ditto. * libc/sys/linux/stdlib/regex2.h: Ditto. * libc/sys/linux/stdlib/regexec.c: Ditto. * libc/sys/linux/stdlib/regfree.c: Ditto. * libc/sys/linux/stdlib/utils.h: Ditto. * libc/sys/linux/stdlib/wordexp.c: Ditto. * libc/sys/linux/stdlib/wordfree.c: Ditto. * libc/sys/linux/sys/dlfcn.h: Ditto. * libc/sys/linux/sys/elfclass.h: Ditto. * libc/sys/linux/sys/event.h: Ditto. * libc/sys/linux/sys/ioccom.h: Ditto. * libc/sys/linux/sys/libc-tsd.h: Ditto. * libc/sys/linux/sys/link.h: Ditto. * libc/sys/linux/sys/lock.h: Ditto. * libc/sys/linux/sys/param.h: Ditto. * libc/sys/linux/sys/socket.h: Ditto. * libc/sys/linux/sys/sockio.h: Ditto.
775 lines
22 KiB
C
775 lines
22 KiB
C
/* Linuxthreads - a simple clone()-based implementation of Posix */
|
|
/* threads for Linux. */
|
|
/* Copyright (C) 1998 Xavier Leroy (Xavier.Leroy@inria.fr) */
|
|
/* */
|
|
/* This program is free software; you can redistribute it and/or */
|
|
/* modify it under the terms of the GNU Library General Public License */
|
|
/* as published by the Free Software Foundation; either version 2 */
|
|
/* of the License, or (at your option) any later version. */
|
|
/* */
|
|
/* This program is distributed in the hope that it will be useful, */
|
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
/* GNU Library General Public License for more details. */
|
|
|
|
/* Internal locks */
|
|
|
|
#include <errno.h>
|
|
#include <sched.h>
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
#include <limits.h>
|
|
#include "pthread.h"
|
|
#include "internals.h"
|
|
#include "spinlock.h"
|
|
#include "restart.h"
|
|
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
static void __pthread_acquire(int * spinlock);
|
|
|
|
static inline void __pthread_release(int * spinlock)
|
|
{
|
|
WRITE_MEMORY_BARRIER();
|
|
*spinlock = __LT_SPINLOCK_INIT;
|
|
__asm __volatile ("" : "=m" (*spinlock) : "0" (*spinlock));
|
|
}
|
|
#endif
|
|
|
|
|
|
/* The status field of a spinlock is a pointer whose least significant
|
|
bit is a locked flag.
|
|
|
|
Thus the field values have the following meanings:
|
|
|
|
status == 0: spinlock is free
|
|
status == 1: spinlock is taken; no thread is waiting on it
|
|
|
|
(status & 1) == 1: spinlock is taken and (status & ~1L) is a
|
|
pointer to the first waiting thread; other
|
|
waiting threads are linked via the p_nextlock
|
|
field.
|
|
(status & 1) == 0: same as above, but spinlock is not taken.
|
|
|
|
The waiting list is not sorted by priority order.
|
|
Actually, we always insert at top of list (sole insertion mode
|
|
that can be performed without locking).
|
|
For __pthread_unlock, we perform a linear search in the list
|
|
to find the highest-priority, oldest waiting thread.
|
|
This is safe because there are no concurrent __pthread_unlock
|
|
operations -- only the thread that locked the mutex can unlock it. */
|
|
|
|
|
|
void internal_function __pthread_lock(struct _pthread_fastlock * lock,
|
|
pthread_descr self)
|
|
{
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
long oldstatus, newstatus;
|
|
int successful_seizure, spurious_wakeup_count;
|
|
int spin_count;
|
|
#endif
|
|
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
{
|
|
__pthread_acquire(&lock->__spinlock);
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
/* First try it without preparation. Maybe it's a completely
|
|
uncontested lock. */
|
|
if (lock->__status == 0 && __compare_and_swap (&lock->__status, 0, 1))
|
|
return;
|
|
|
|
spurious_wakeup_count = 0;
|
|
spin_count = 0;
|
|
|
|
again:
|
|
|
|
/* On SMP, try spinning to get the lock. */
|
|
|
|
if (__pthread_smp_kernel) {
|
|
int max_count = lock->__spinlock * 2 + 10;
|
|
|
|
if (max_count > MAX_ADAPTIVE_SPIN_COUNT)
|
|
max_count = MAX_ADAPTIVE_SPIN_COUNT;
|
|
|
|
for (spin_count = 0; spin_count < max_count; spin_count++) {
|
|
if (((oldstatus = lock->__status) & 1) == 0) {
|
|
if(__compare_and_swap(&lock->__status, oldstatus, oldstatus | 1))
|
|
{
|
|
if (spin_count)
|
|
lock->__spinlock += (spin_count - lock->__spinlock) / 8;
|
|
READ_MEMORY_BARRIER();
|
|
return;
|
|
}
|
|
}
|
|
#ifdef BUSY_WAIT_NOP
|
|
BUSY_WAIT_NOP;
|
|
#endif
|
|
__asm __volatile ("" : "=m" (lock->__status) : "0" (lock->__status));
|
|
}
|
|
|
|
lock->__spinlock += (spin_count - lock->__spinlock) / 8;
|
|
}
|
|
|
|
/* No luck, try once more or suspend. */
|
|
|
|
do {
|
|
oldstatus = lock->__status;
|
|
successful_seizure = 0;
|
|
|
|
if ((oldstatus & 1) == 0) {
|
|
newstatus = oldstatus | 1;
|
|
successful_seizure = 1;
|
|
} else {
|
|
if (self == NULL)
|
|
self = thread_self();
|
|
newstatus = (long) self | 1;
|
|
}
|
|
|
|
if (self != NULL) {
|
|
THREAD_SETMEM(self, p_nextlock, (pthread_descr) (oldstatus & ~1L));
|
|
/* Make sure the store in p_nextlock completes before performing
|
|
the compare-and-swap */
|
|
MEMORY_BARRIER();
|
|
}
|
|
} while(! __compare_and_swap(&lock->__status, oldstatus, newstatus));
|
|
|
|
/* Suspend with guard against spurious wakeup.
|
|
This can happen in pthread_cond_timedwait_relative, when the thread
|
|
wakes up due to timeout and is still on the condvar queue, and then
|
|
locks the queue to remove itself. At that point it may still be on the
|
|
queue, and may be resumed by a condition signal. */
|
|
|
|
if (!successful_seizure) {
|
|
for (;;) {
|
|
suspend(self);
|
|
if (self->p_nextlock != NULL) {
|
|
/* Count resumes that don't belong to us. */
|
|
spurious_wakeup_count++;
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
goto again;
|
|
}
|
|
|
|
/* Put back any resumes we caught that don't belong to us. */
|
|
while (spurious_wakeup_count--)
|
|
restart(self);
|
|
|
|
READ_MEMORY_BARRIER();
|
|
#endif
|
|
}
|
|
|
|
int __pthread_unlock(struct _pthread_fastlock * lock)
|
|
{
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
long oldstatus;
|
|
pthread_descr thr, * ptr, * maxptr;
|
|
int maxprio;
|
|
#endif
|
|
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
{
|
|
__pthread_release(&lock->__spinlock);
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
WRITE_MEMORY_BARRIER();
|
|
|
|
again:
|
|
while ((oldstatus = lock->__status) == 1) {
|
|
if (__compare_and_swap_with_release_semantics(&lock->__status,
|
|
oldstatus, 0))
|
|
return 0;
|
|
}
|
|
|
|
/* Find thread in waiting queue with maximal priority */
|
|
ptr = (pthread_descr *) &lock->__status;
|
|
thr = (pthread_descr) (oldstatus & ~1L);
|
|
maxprio = 0;
|
|
maxptr = ptr;
|
|
|
|
/* Before we iterate over the wait queue, we need to execute
|
|
a read barrier, otherwise we may read stale contents of nodes that may
|
|
just have been inserted by other processors. One read barrier is enough to
|
|
ensure we have a stable list; we don't need one for each pointer chase
|
|
through the list, because we are the owner of the lock; other threads
|
|
can only add nodes at the front; if a front node is consistent,
|
|
the ones behind it must also be. */
|
|
|
|
READ_MEMORY_BARRIER();
|
|
|
|
while (thr != 0) {
|
|
if (thr->p_priority >= maxprio) {
|
|
maxptr = ptr;
|
|
maxprio = thr->p_priority;
|
|
}
|
|
ptr = &(thr->p_nextlock);
|
|
thr = *ptr;
|
|
}
|
|
|
|
/* Remove max prio thread from waiting list. */
|
|
if (maxptr == (pthread_descr *) &lock->__status) {
|
|
/* If max prio thread is at head, remove it with compare-and-swap
|
|
to guard against concurrent lock operation. This removal
|
|
also has the side effect of marking the lock as released
|
|
because the new status comes from thr->p_nextlock whose
|
|
least significant bit is clear. */
|
|
thr = (pthread_descr) (oldstatus & ~1L);
|
|
if (! __compare_and_swap_with_release_semantics
|
|
(&lock->__status, oldstatus, (long)(thr->p_nextlock)))
|
|
goto again;
|
|
} else {
|
|
/* No risk of concurrent access, remove max prio thread normally.
|
|
But in this case we must also flip the least significant bit
|
|
of the status to mark the lock as released. */
|
|
thr = *maxptr;
|
|
*maxptr = thr->p_nextlock;
|
|
|
|
/* Ensure deletion from linked list completes before we
|
|
release the lock. */
|
|
WRITE_MEMORY_BARRIER();
|
|
|
|
do {
|
|
oldstatus = lock->__status;
|
|
} while (!__compare_and_swap_with_release_semantics(&lock->__status,
|
|
oldstatus, oldstatus & ~1L));
|
|
}
|
|
|
|
/* Wake up the selected waiting thread. Woken thread can check
|
|
its own p_nextlock field for NULL to detect that it has been removed. No
|
|
barrier is needed here, since restart() and suspend() take
|
|
care of memory synchronization. */
|
|
|
|
thr->p_nextlock = NULL;
|
|
restart(thr);
|
|
|
|
return 0;
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
* Alternate fastlocks do not queue threads directly. Instead, they queue
|
|
* these wait queue node structures. When a timed wait wakes up due to
|
|
* a timeout, it can leave its wait node in the queue (because there
|
|
* is no safe way to remove from the quue). Some other thread will
|
|
* deallocate the abandoned node.
|
|
*/
|
|
|
|
|
|
struct wait_node {
|
|
struct wait_node *next; /* Next node in null terminated linked list */
|
|
pthread_descr thr; /* The thread waiting with this node */
|
|
int abandoned; /* Atomic flag */
|
|
};
|
|
|
|
static long wait_node_free_list;
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
static int wait_node_free_list_spinlock;
|
|
#endif
|
|
|
|
/* Allocate a new node from the head of the free list using an atomic
|
|
operation, or else using malloc if that list is empty. A fundamental
|
|
assumption here is that we can safely access wait_node_free_list->next.
|
|
That's because we never free nodes once we allocate them, so a pointer to a
|
|
node remains valid indefinitely. */
|
|
|
|
static struct wait_node *wait_node_alloc(void)
|
|
{
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
long oldvalue, newvalue;
|
|
#endif
|
|
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
{
|
|
struct wait_node *new_node = 0;
|
|
|
|
__pthread_acquire(&wait_node_free_list_spinlock);
|
|
if (wait_node_free_list != 0) {
|
|
new_node = (struct wait_node *) wait_node_free_list;
|
|
wait_node_free_list = (long) new_node->next;
|
|
}
|
|
WRITE_MEMORY_BARRIER();
|
|
wait_node_free_list_spinlock = 0;
|
|
|
|
if (new_node == 0)
|
|
return malloc(sizeof *wait_node_alloc());
|
|
|
|
return new_node;
|
|
}
|
|
#endif
|
|
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
do {
|
|
oldvalue = wait_node_free_list;
|
|
|
|
if (oldvalue == 0)
|
|
return malloc(sizeof *wait_node_alloc());
|
|
|
|
/* Ensure we don't read stale next link through oldvalue pointer. */
|
|
READ_MEMORY_BARRIER();
|
|
newvalue = (long) ((struct wait_node *) oldvalue)->next;
|
|
} while (! __compare_and_swap(&wait_node_free_list, oldvalue, newvalue));
|
|
|
|
return (struct wait_node *) oldvalue;
|
|
#endif
|
|
}
|
|
|
|
/* Return a node to the head of the free list using an atomic
|
|
operation. */
|
|
|
|
static void wait_node_free(struct wait_node *wn)
|
|
{
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
long oldvalue, newvalue;
|
|
#endif
|
|
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
{
|
|
__pthread_acquire(&wait_node_free_list_spinlock);
|
|
wn->next = (struct wait_node *) wait_node_free_list;
|
|
wait_node_free_list = (long) wn;
|
|
WRITE_MEMORY_BARRIER();
|
|
wait_node_free_list_spinlock = 0;
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
do {
|
|
oldvalue = wait_node_free_list;
|
|
wn->next = (struct wait_node *) oldvalue;
|
|
newvalue = (long) wn;
|
|
/* Ensure node contents are written before we swap it into the list. */
|
|
WRITE_MEMORY_BARRIER();
|
|
} while (! __compare_and_swap(&wait_node_free_list, oldvalue, newvalue));
|
|
#endif
|
|
}
|
|
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
|
|
/* Remove a wait node from the specified queue. It is assumed
|
|
that the removal takes place concurrently with only atomic insertions at the
|
|
head of the queue. */
|
|
|
|
static void wait_node_dequeue(struct wait_node **pp_head,
|
|
struct wait_node **pp_node,
|
|
struct wait_node *p_node)
|
|
{
|
|
/* If the node is being deleted from the head of the
|
|
list, it must be deleted using atomic compare-and-swap.
|
|
Otherwise it can be deleted in the straightforward way. */
|
|
|
|
if (pp_node == pp_head) {
|
|
/* We don't need a read barrier between these next two loads,
|
|
because it is assumed that the caller has already ensured
|
|
the stability of *p_node with respect to p_node. */
|
|
|
|
long oldvalue = (long) p_node;
|
|
long newvalue = (long) p_node->next;
|
|
|
|
if (__compare_and_swap((long *) pp_node, oldvalue, newvalue))
|
|
return;
|
|
|
|
/* Oops! Compare and swap failed, which means the node is
|
|
no longer first. We delete it using the ordinary method. But we don't
|
|
know the identity of the node which now holds the pointer to the node
|
|
being deleted, so we must search from the beginning. */
|
|
|
|
for (pp_node = pp_head; p_node != *pp_node; ) {
|
|
pp_node = &(*pp_node)->next;
|
|
READ_MEMORY_BARRIER(); /* Stabilize *pp_node for next iteration. */
|
|
}
|
|
}
|
|
|
|
*pp_node = p_node->next;
|
|
return;
|
|
}
|
|
|
|
#endif
|
|
|
|
void __pthread_alt_lock(struct _pthread_fastlock * lock,
|
|
pthread_descr self)
|
|
{
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
long oldstatus, newstatus;
|
|
#endif
|
|
struct wait_node wait_node;
|
|
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
{
|
|
int suspend_needed = 0;
|
|
__pthread_acquire(&lock->__spinlock);
|
|
|
|
if (lock->__status == 0)
|
|
lock->__status = 1;
|
|
else {
|
|
if (self == NULL)
|
|
self = thread_self();
|
|
|
|
wait_node.abandoned = 0;
|
|
wait_node.next = (struct wait_node *) lock->__status;
|
|
wait_node.thr = self;
|
|
lock->__status = (long) &wait_node;
|
|
suspend_needed = 1;
|
|
}
|
|
|
|
__pthread_release(&lock->__spinlock);
|
|
|
|
if (suspend_needed)
|
|
suspend (self);
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
do {
|
|
oldstatus = lock->__status;
|
|
if (oldstatus == 0) {
|
|
newstatus = 1;
|
|
} else {
|
|
if (self == NULL)
|
|
self = thread_self();
|
|
wait_node.thr = self;
|
|
newstatus = (long) &wait_node;
|
|
}
|
|
wait_node.abandoned = 0;
|
|
wait_node.next = (struct wait_node *) oldstatus;
|
|
/* Make sure the store in wait_node.next completes before performing
|
|
the compare-and-swap */
|
|
MEMORY_BARRIER();
|
|
} while(! __compare_and_swap(&lock->__status, oldstatus, newstatus));
|
|
|
|
/* Suspend. Note that unlike in __pthread_lock, we don't worry
|
|
here about spurious wakeup. That's because this lock is not
|
|
used in situations where that can happen; the restart can
|
|
only come from the previous lock owner. */
|
|
|
|
if (oldstatus != 0)
|
|
suspend(self);
|
|
|
|
READ_MEMORY_BARRIER();
|
|
#endif
|
|
}
|
|
|
|
/* Timed-out lock operation; returns 0 to indicate timeout. */
|
|
|
|
int __pthread_alt_timedlock(struct _pthread_fastlock * lock,
|
|
pthread_descr self, const struct timespec *abstime)
|
|
{
|
|
long oldstatus = 0;
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
long newstatus;
|
|
#endif
|
|
struct wait_node *p_wait_node = wait_node_alloc();
|
|
|
|
/* Out of memory, just give up and do ordinary lock. */
|
|
if (p_wait_node == 0) {
|
|
__pthread_alt_lock(lock, self);
|
|
return 1;
|
|
}
|
|
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
{
|
|
__pthread_acquire(&lock->__spinlock);
|
|
|
|
if (lock->__status == 0)
|
|
lock->__status = 1;
|
|
else {
|
|
if (self == NULL)
|
|
self = thread_self();
|
|
|
|
p_wait_node->abandoned = 0;
|
|
p_wait_node->next = (struct wait_node *) lock->__status;
|
|
p_wait_node->thr = self;
|
|
lock->__status = (long) p_wait_node;
|
|
oldstatus = 1; /* force suspend */
|
|
}
|
|
|
|
__pthread_release(&lock->__spinlock);
|
|
goto suspend;
|
|
}
|
|
#endif
|
|
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
do {
|
|
oldstatus = lock->__status;
|
|
if (oldstatus == 0) {
|
|
newstatus = 1;
|
|
} else {
|
|
if (self == NULL)
|
|
self = thread_self();
|
|
p_wait_node->thr = self;
|
|
newstatus = (long) p_wait_node;
|
|
}
|
|
p_wait_node->abandoned = 0;
|
|
p_wait_node->next = (struct wait_node *) oldstatus;
|
|
/* Make sure the store in wait_node.next completes before performing
|
|
the compare-and-swap */
|
|
MEMORY_BARRIER();
|
|
} while(! __compare_and_swap(&lock->__status, oldstatus, newstatus));
|
|
#endif
|
|
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
suspend:
|
|
#endif
|
|
|
|
/* If we did not get the lock, do a timed suspend. If we wake up due
|
|
to a timeout, then there is a race; the old lock owner may try
|
|
to remove us from the queue. This race is resolved by us and the owner
|
|
doing an atomic testandset() to change the state of the wait node from 0
|
|
to 1. If we succeed, then it's a timeout and we abandon the node in the
|
|
queue. If we fail, it means the owner gave us the lock. */
|
|
|
|
if (oldstatus != 0) {
|
|
if (timedsuspend(self, abstime) == 0) {
|
|
if (!testandset(&p_wait_node->abandoned))
|
|
return 0; /* Timeout! */
|
|
|
|
/* Eat oustanding resume from owner, otherwise wait_node_free() below
|
|
will race with owner's wait_node_dequeue(). */
|
|
suspend(self);
|
|
}
|
|
}
|
|
|
|
wait_node_free(p_wait_node);
|
|
|
|
READ_MEMORY_BARRIER();
|
|
|
|
return 1; /* Got the lock! */
|
|
}
|
|
|
|
void __pthread_alt_unlock(struct _pthread_fastlock *lock)
|
|
{
|
|
struct wait_node *p_node, **pp_node, *p_max_prio, **pp_max_prio;
|
|
struct wait_node ** const pp_head = (struct wait_node **) &lock->__status;
|
|
int maxprio;
|
|
|
|
WRITE_MEMORY_BARRIER();
|
|
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
{
|
|
__pthread_acquire(&lock->__spinlock);
|
|
}
|
|
#endif
|
|
|
|
while (1) {
|
|
|
|
/* If no threads are waiting for this lock, try to just
|
|
atomically release it. */
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
{
|
|
if (lock->__status == 0 || lock->__status == 1) {
|
|
lock->__status = 0;
|
|
break;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
else
|
|
#endif
|
|
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
{
|
|
long oldstatus = lock->__status;
|
|
if (oldstatus == 0 || oldstatus == 1) {
|
|
if (__compare_and_swap_with_release_semantics (&lock->__status, oldstatus, 0))
|
|
break;
|
|
else
|
|
continue;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/* Process the entire queue of wait nodes. Remove all abandoned
|
|
wait nodes and put them into the global free queue, and
|
|
remember the one unabandoned node which refers to the thread
|
|
having the highest priority. */
|
|
|
|
pp_max_prio = pp_node = pp_head;
|
|
p_max_prio = p_node = *pp_head;
|
|
maxprio = INT_MIN;
|
|
|
|
READ_MEMORY_BARRIER(); /* Prevent access to stale data through p_node */
|
|
|
|
while (p_node != (struct wait_node *) 1) {
|
|
int prio;
|
|
|
|
if (p_node->abandoned) {
|
|
/* Remove abandoned node. */
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
*pp_node = p_node->next;
|
|
#endif
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
else
|
|
#endif
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
wait_node_dequeue(pp_head, pp_node, p_node);
|
|
#endif
|
|
wait_node_free(p_node);
|
|
/* Note that the next assignment may take us to the beginning
|
|
of the queue, to newly inserted nodes, if pp_node == pp_head.
|
|
In that case we need a memory barrier to stabilize the first of
|
|
these new nodes. */
|
|
p_node = *pp_node;
|
|
if (pp_node == pp_head)
|
|
READ_MEMORY_BARRIER(); /* No stale reads through p_node */
|
|
continue;
|
|
} else if ((prio = p_node->thr->p_priority) >= maxprio) {
|
|
/* Otherwise remember it if its thread has a higher or equal priority
|
|
compared to that of any node seen thus far. */
|
|
maxprio = prio;
|
|
pp_max_prio = pp_node;
|
|
p_max_prio = p_node;
|
|
}
|
|
|
|
/* This canno6 jump backward in the list, so no further read
|
|
barrier is needed. */
|
|
pp_node = &p_node->next;
|
|
p_node = *pp_node;
|
|
}
|
|
|
|
/* If all threads abandoned, go back to top */
|
|
if (maxprio == INT_MIN)
|
|
continue;
|
|
|
|
ASSERT (p_max_prio != (struct wait_node *) 1);
|
|
|
|
/* Now we want to to remove the max priority thread's wait node from
|
|
the list. Before we can do this, we must atomically try to change the
|
|
node's abandon state from zero to nonzero. If we succeed, that means we
|
|
have the node that we will wake up. If we failed, then it means the
|
|
thread timed out and abandoned the node in which case we repeat the
|
|
whole unlock operation. */
|
|
|
|
if (!testandset(&p_max_prio->abandoned)) {
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
*pp_max_prio = p_max_prio->next;
|
|
#endif
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
else
|
|
#endif
|
|
#if defined HAS_COMPARE_AND_SWAP
|
|
wait_node_dequeue(pp_head, pp_max_prio, p_max_prio);
|
|
#endif
|
|
restart(p_max_prio->thr);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#if defined TEST_FOR_COMPARE_AND_SWAP
|
|
if (!__pthread_has_cas)
|
|
#endif
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
{
|
|
__pthread_release(&lock->__spinlock);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
/* Compare-and-swap emulation with a spinlock */
|
|
|
|
#ifdef TEST_FOR_COMPARE_AND_SWAP
|
|
int __pthread_has_cas = 0;
|
|
#endif
|
|
|
|
#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
|
|
|
|
int __pthread_compare_and_swap(long * ptr, long oldval, long newval,
|
|
int * spinlock)
|
|
{
|
|
int res;
|
|
|
|
__pthread_acquire(spinlock);
|
|
|
|
if (*ptr == oldval) {
|
|
*ptr = newval; res = 1;
|
|
} else {
|
|
res = 0;
|
|
}
|
|
|
|
__pthread_release(spinlock);
|
|
|
|
return res;
|
|
}
|
|
|
|
/* This function is called if the inlined test-and-set
|
|
in __pthread_compare_and_swap() failed */
|
|
|
|
/* The retry strategy is as follows:
|
|
- We test and set the spinlock MAX_SPIN_COUNT times, calling
|
|
sched_yield() each time. This gives ample opportunity for other
|
|
threads with priority >= our priority to make progress and
|
|
release the spinlock.
|
|
- If a thread with priority < our priority owns the spinlock,
|
|
calling sched_yield() repeatedly is useless, since we're preventing
|
|
the owning thread from making progress and releasing the spinlock.
|
|
So, after MAX_SPIN_LOCK attemps, we suspend the calling thread
|
|
using nanosleep(). This again should give time to the owning thread
|
|
for releasing the spinlock.
|
|
Notice that the nanosleep() interval must not be too small,
|
|
since the kernel does busy-waiting for short intervals in a realtime
|
|
process (!). The smallest duration that guarantees thread
|
|
suspension is currently 2ms.
|
|
- When nanosleep() returns, we try again, doing MAX_SPIN_COUNT
|
|
sched_yield(), then sleeping again if needed. */
|
|
|
|
static void __pthread_acquire(int * spinlock)
|
|
{
|
|
int cnt = 0;
|
|
struct timespec tm;
|
|
|
|
READ_MEMORY_BARRIER();
|
|
|
|
while (testandset(spinlock)) {
|
|
if (cnt < MAX_SPIN_COUNT) {
|
|
sched_yield();
|
|
cnt++;
|
|
} else {
|
|
tm.tv_sec = 0;
|
|
tm.tv_nsec = SPIN_SLEEP_DURATION;
|
|
nanosleep(&tm, NULL);
|
|
cnt = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|