freebsd-dev/libexec
John Polstra 630df077ab Solve the dynamic linker's problems with multithreaded programs once
and for all (I hope).  Packages such as wine, JDK, and linuxthreads
should no longer have any problems with re-entering the dynamic
linker.

This commit replaces the locking used in the dynamic linker with a
new spinlock-based reader/writer lock implementation.  Brian
Fundakowski Feldman <green> argued for this from the very beginning,
but it took me a long time to come around to his point of view.
Spinlocks are the only kinds of locks that work with all thread
packages.  But on uniprocessor systems they can be inefficient,
because while a contender for the lock is spinning the holder of the
lock cannot make any progress toward releasing it.  To alleviate
this disadvantage I have borrowed a trick from Sleepycat's Berkeley
DB implementation.  When spinning for a lock, the requester does a
nanosleep() call for 1 usec. each time around the loop.  This will
generally yield the CPU to other threads, allowing the lock holder
to finish its business and release the lock.  I chose 1 usec. as the
minimum sleep which would with reasonable certainty not be rounded
down to 0.

The formerly machine-independent file "lockdflt.c" has been moved
into the architecture-specific subdirectories by repository copy.
It now contains the machine-dependent spinlocking code.  For the
spinlocks I used the very nifty "simple, non-scalable reader-preference
lock" which I found at

  <http://www.cs.rochester.edu/u/scott/synchronization/pseudocode/rw.html>

on all CPUs except the 80386 (the specific CPU model, not the
architecture).  The 80386 CPU doesn't support the necessary "cmpxchg"
instruction, so on that CPU a simple exclusive test-and-set lock
is used instead.  80386 CPUs are detected at initialization time by
trying to execute "cmpxchg" and catching the resulting SIGILL
signal.

To reduce contention for the locks, I have revamped a couple of
key data structures, permitting all common operations to be done
under non-exclusive (reader) locking.  The only operations that
require exclusive locking now are the rare intrusive operations
such as dlopen() and dlclose().

The dllockinit() interface is now deprecated.  It still exists,
but only as a do-nothing stub.  I plan to remove it as soon as is
reasonably possible.  (From the very beginning it was clearly
labeled as experimental and subject to change.)  As far as I know,
only the linuxthreads port uses dllockinit().  This interface turned
out to have several problems.  As one example, when the dynamic
linker called a client-supplied locking function, that function
sometimes needed lazy binding, causing re-entry into the dynamic
linker and a big looping mess.  And in any case, it turned out to be
too burdensome to require threads packages to register themselves
with the dynamic linker.
2000-07-08 04:10:38 +00:00
..
atrun Don't uselessly set MANDEPEND (it isn't used in this Makefile, and isn't 2000-05-15 15:01:13 +00:00
bootpd
comsat
fingerd Support logging for IPv6 remote host. 2000-02-18 07:08:03 +00:00
ftpd Fix a problem in the virtual host address compare code which caused 2000-06-26 05:36:09 +00:00
getNAME
getty Changed setflags() to set_flags(). This fixes world breakage due to 2000-01-28 07:12:03 +00:00
mail.local
makekey
mknetid
named-xfer
pppoed
rbootd
revnetgroup
rexecd Man page fixups 2000-05-15 14:06:07 +00:00
rlogind Use libcrypto instead of libdes. 2000-02-24 21:18:08 +00:00
rpc.rquotad Fix various man pages to stop abusing the .Bx macro to generate the 2000-01-23 02:18:19 +00:00
rpc.rstatd
rpc.rusersd
rpc.rwalld
rpc.sprayd
rshd Plug the hole where rshd would bypass a proper .rhosts check if the 2000-07-05 17:47:17 +00:00
rtld-aout Move the man pages for the a.out dynamic linker into the 1aout 2000-01-29 03:13:49 +00:00
rtld-elf Solve the dynamic linker's problems with multithreaded programs once 2000-07-08 04:10:38 +00:00
smrsh
talkd
telnetd Minor mdoc cleanup. 2000-05-05 02:21:45 +00:00
tftpd
uucpd IPv6 support. 2000-05-14 18:01:05 +00:00
xtend
ypxfr Spelling fix: transfered --> transferred 2000-06-02 21:22:09 +00:00
Makefile Wrap uucpd behind the NOUUCP knob. 2000-03-24 18:21:09 +00:00
Makefile.inc