Commit Graph

486 Commits

Author SHA1 Message Date
Daniel Eischen
f434cd45ed Remove (int) file descriptor locking. It should be up to the
application to provide locking for I/O operations.  This doesn't
break any of my tests, but the old behavior can be restored by
compiling with _FDLOCKS_ENABLED.  This will eventually be removed
when it is obvious it does not cause any problems.

Remove most of flockfile implementation, with the exception of
flockfile_debug.

Make error messages more informational (submitted by Mike Heffner
<spock@techfour.net>, who's now known as mikeh@FreeBSD.org).
2001-02-11 22:07:32 +00:00
Nik Clayton
7b79d3ab37 Fix typo.
PR:             docs/23936
Submitted by:   Garret Rooney <rooneg@rpi.edu>
2001-02-02 03:32:03 +00:00
Ruslan Ermilov
d0353b836e mdoc(7) police: split punctuation characters + misc fixes. 2001-02-01 16:38:02 +00:00
Daniel Eischen
f8a19b12fb s/_thread_sys_write/__sys_write/
Submitted by:	Mike Heffner <mheffner@vt.edu>
2001-01-31 02:16:57 +00:00
Daniel Eischen
f47892a9f7 Unbreak world by correctly specifying the prototype for __sys_aio_suspend.
A make buildworld was done but not with the committed pthread_private.h.

Reported by:	Manfred Antar <null@pozo.com>
2001-01-29 18:59:53 +00:00
Daniel Eischen
221b1e69c5 _exit in libc is now __sys_exit not __sys__exit.
Add another check for thread library initialization (jdp, we
really need a way to get _thread_init called at program start
before any constructors are run).
2001-01-29 03:24:23 +00:00
Daniel Eischen
75f7221ee6 -pthread -> -lc_r 2001-01-24 13:41:04 +00:00
Daniel Eischen
e5106342c6 Add weak definitions for wrapped system calls. In general:
_foo - wrapped system call
	foo - weak definition to _foo

and for cancellation points:

	_foo - wrapped system call
	__foo - enter cancellation point, call _foo(), leave
	        cancellation point
	foo - weak definition to __foo

Change use of global _thread_run to call a function to get the
currently running thread.

Make all pthread_foo functions weak definitions to _pthread_foo,
where _pthread_foo is the implementation.  This allows an application
to provide its own pthread functions.

Provide slightly different versions of pthread_mutex_lock and
pthread_mutex_init so that we can tell the difference between
a libc mutex and an application mutex.  Threads holding mutexes
internal to libc should never be allowed to exit, call signal
handlers, or cancel.

Approved by:	-arch
2001-01-24 13:03:38 +00:00
David E. O'Brien
cad1dd7bb4 Force strong references to several pthread_* functions which are weakly
referenced to by libgcc.a.

This is needed when linking statically as SVR4 (ie, ELF) behavior is to only
link in a module if it satisfies an undefined strong reference from somewhere.
(this surprises a lot of people) Things are different when using shared libs,
the entire library and its modules and their symbols are available at run-time
(when the weak reference is seen to still be unsatisfied and is satisfied on
the spot), this is not the case with static libs.

Thus one can have a static binary with unresolved week references, and at
run-time dereference a NULL pointer.

Submitted by:	eischen
2001-01-06 06:07:52 +00:00
Poul-Henning Kamp
f42abb1fef Use macro API to <sys/queue.h>
Submitted by:	"Peter Avalos" <pavalos@theshell.com>
Reviewed by:	/sbin/md5 [*]

[*] This line appears courtesy of Mr. Warner Losch, all rights reversed.
2000-12-31 10:28:01 +00:00
Ruslan Ermilov
4263595653 Prepare for mdoc(7)NG. 2000-12-29 14:08:20 +00:00
Daniel Eischen
9ffc4537c8 When retrieving the time of day in nanosleep(), store it in the
global time of day.  This costs us nothing, but is a bit of a hack
to work around a process blocking and not having the time updated
by an ITIMER_PROF signal.

PR:		23679
2000-12-20 17:04:12 +00:00
Daniel Eischen
d73eb8c8ca Enable check for pending signals after calling a signal handler.
Restoration of a threads signal mask after invocation of a signal
handler may allow pending signals to become deliverable.

PR:		23647
2000-12-20 16:55:57 +00:00
Ruslan Ermilov
c23155a43a mdoc(7) police: Er macro usage cleanup. 2000-11-22 16:02:00 +00:00
Daniel Eischen
47c1571785 Change a "while {}" loop to a "do {} while" to allow it to be
executed at least once, fixing pthread_mutex_lock() for recursive
mutex lock attempts.

Correctly set a threads signal mask while it is executing a signal
handler.  The mask should be the union of its current mask, the
signal being handled, and the mask from the signal action.

Reported by: Dan Nelson <dnelson@emsphone.com>

MFC Candidate
2000-11-20 13:12:44 +00:00
Daniel Eischen
499c499c61 Fix MD macros to work for alpha. Without this fix, threads under alpha
seem to be totally broke.

MFC Candidate

Submitted by:	gallatin
2000-11-20 01:57:19 +00:00
Daniel Eischen
f17033e38d Fix a bug where a statically initialized condition variable
was not getting properly initialized in pthread_cond_signal()
and pthread_cond_broadcast().  Reportedly, this can cause
an application to die.

MFC candidate

Submitted by:	ade
2000-11-16 22:50:33 +00:00
Daniel Eischen
810888e2f8 Delete 4 lines of misleading/incorrect comments. 2000-11-16 19:15:56 +00:00
Daniel Eischen
eb4463fde6 When entering the scheduler from the signal handler, tell
the kernel to (re)use the alternate signal stack.  In this
case, we don't return normally from the signal handler,
so the kernel still thinks we are using the signal stack.
The fixes a nasty bug where the signal handler can start
fiddling with the stack of a thread while the handler is
actually running on the same stack.

MFC candidate
2000-11-14 20:00:19 +00:00
Ruslan Ermilov
b5c508fba3 Use Fx macro wherever possible. 2000-11-14 11:20:58 +00:00
David E. O'Brien
fe17fef5d2 Bump the shared lib version. There seems to have been an incompatible
change committed to RELENG_4 where a bump there is now necessary.
We've got to go before RELENG_4 does.
2000-11-14 02:46:23 +00:00
Daniel Eischen
00e550955e Correct the logic for checking the emptiness of the waiting queue.
This fixes a potential problem where the file descriptors would not
be polled causing waiting threads to stay waiting.  Doh!

MFC candidate.
2000-11-11 22:20:36 +00:00
Daniel Eischen
b5a8a15c2f Don't needlessly poll file descriptors when there are no
file descriptors needing to be polled (Doh!).  Reported
by Dan Nelson <dnelson@emsphone.com>.

Don't install and start the scheduling timer until the
first thread is created.  This prevents the overhead of
having a periodic scheduling signal in a single threaded
program.  Reported by Dan Nelson <dnelson@emsphone.com>.

Allow builtin longjmps out of application installed
signal handlers without the need perform any post-handler
cleanup:

  o Change signal handling to save the threads interrupted
    context on the stack.  The threads current context is
    now always stored in the same place (in the pthread).
    If and when a signal handler returns, the interrupted
    context is copied back to the storage area in the pthread.

  o Before calling invoking a signal handler for a thread,
    back the thread out of any internal waiting queues
    (mutex, CV, join, etc) to which it belongs.

Rework uthread_info.c a bit to make it easier to change
the format of a thread dump.

Use an alternal signal stack for the thread library's
signal handler.  This allows us to fiddle with the main
threads stack without fear of it being in use.

Reviewed by:	jasone
2000-11-09 05:08:26 +00:00
Daniel Eischen
9a6b83bf3b Prevent the thread-safe version of kevent from getting
into an infinite loop when a timeout value is supplied
and the timeout expires.

Reported by:	Dan Nelson <dnelson@emsphone.com>
Reviewed by:	jasone, jlemon
2000-11-09 05:00:06 +00:00
John Polstra
a9bda22cd6 At the beginning of pthread_mutex_lock(), call _thread_init() if
necessary.  This works around a bug in old versions of libgcc_r.a
which are statically linked into old executables.
2000-11-01 20:19:07 +00:00
Daniel Eischen
c418675341 Make pthread_kill() know about temporary signal handlers installed
by sigwait().  This prevents a signal from being sent to the process
when there are no application installed signal handlers.

Correct a typo in sigwait (foo -> foo[i]).
2000-10-25 11:46:07 +00:00
Daniel Eischen
2fbba8b1b8 We use ___setjmp (non-signal saving) to setup a signal frame. When
adding a signal frame to a thread, be sure to label the context
correctly so we don't restore an uninitialized process mask.

Reported by:	kimc@W8HD.ORG and Andrey Rouskol <anry@sovintel.ru>
2000-10-22 18:35:11 +00:00
Peter Wemm
100063a74b Try and get libc_r to compile again on the alpha after deischen's commit 2000-10-17 06:31:40 +00:00
Brian Somers
9c8ec4f794 #include <sys/types.h> 2000-10-15 20:04:09 +00:00
Daniel Eischen
b4145b0bfa Enable _PTHREADS_INVARIANTS until the recent libc_r changes are
shaken out.
2000-10-13 22:19:50 +00:00
Daniel Eischen
fbeb36e4bf Implement zero system call thread switching. Performance of
thread switches should be on par with that under scheduler
activations.

  o Timing is achieved through the use of a fixed interval
    timer (ITIMER_PROF) to count scheduling ticks instead
    of retrieving the time-of-day upon every thread switch
    and calculating elapsed real time.

  o Polling for I/O readiness is performed once for each
    scheduling tick instead of every thread switch.

  o The non-signal saving/restoring versions of setjmp/longjmp
    are used to save and restore thread contexts.  This may
    allow the removal of _THREAD_SAFE macros from setjmp()
    and longjmp() - needs more investigation.

Change signal handling so that signals are handled in the
context of the thread that is receiving the signal.  When
signals are dispatched to a thread, a special signal handling
frame is created on top of the target threads stack.  The
frame contains the threads saved state information and a new
context in which the thread can run.  The applications signal
handler is invoked through a wrapper routine that knows how
to restore the threads saved state and unwind to previous
frames.

Fix interruption of threads due to signals.  Some states
were being improperly interrupted while other states were
not being interrupted.  This should fix several PRs.

Signal handlers, which are invoked as a result of a process
signal (not by pthread_kill()), are now called with the
code (or siginfo_t if SA_SIGINFO was set in sa_flags) and
sigcontext_t as received from the process signal handler.

Modify the search for a thread to which a signal is delivered.
The search algorithm is now:

  o First thread found in sigwait() with signal in wait mask.
  o First thread found sigsuspend()'d on the signal.
  o Current thread if signal is unmasked.
  o First thread found with signal unmasked.

Collapse machine dependent support into macros defined in
pthread_private.h.  These should probably eventually be moved
into separate MD files.

Change the range of settable priorities to be compliant with
POSIX (0-31).  The threads library uses higher priorities
internally for real-time threads (not yet implemented) and
threads executing signal handlers.  Real-time threads and
threads running signal handlers add 64 and 32, respectively,
to a threads base priority.

Some other small changes and cleanups.

PR:		17757 18559 21943
Reviewed by:	jasone
2000-10-13 22:12:32 +00:00
Maxim Sobolev
24a1dab36f Add thread-safe wrapper for fpathconf(2) syscall.
Reviewed by:	jlemon
2000-09-19 18:01:03 +00:00
Jason Evans
f3ee83c3bf The second call to _thread_kern_sig_defer() in sem_post() should be a call
to _thread_kern_sig_undefer().
2000-08-23 07:59:50 +00:00
Alfred Perlstein
022daa34f2 Fix an off-by-one error in the recursive mutex handling that made it
prematurely release recursive mutexes.

Test case provided by: Bradley T. Hughes <bhughes@trolltech.com>
Reviewed by: deischen
2000-08-13 01:30:36 +00:00
Jason Evans
f8842c0a18 kevent() is not a POSIX cancellation point, so _kevent() need not be
defined.

Remove some unnecessary header file inclusions.
2000-08-08 00:12:35 +00:00
Jonathan Lemon
532c92a865 Add wrapper for kevent() syscall
Noted as missing by: nicolas.leonard@animaths.com
2000-08-07 16:51:56 +00:00
Jason Evans
b167c9a5c1 Make sem_post() safe to call from within a signal handler, as required by
POSIX/SUSv2.
2000-08-01 21:19:09 +00:00
Doug Rabson
678ef1b49e Call _thread_init() from pthread_once() if it has not already been called.
This fixes a segfault in some C++ programs which use exceptions before
main() has been called (i.e. from global constructors).

Reviewed by: deischen
2000-07-21 09:31:13 +00:00
Jason Evans
c1110eb673 pthread_once --> pthread_once_t. 2000-07-19 16:38:07 +00:00
Jason Evans
8e234adf86 Change my email address in the copyright notices for the sake of consistency
(jasone@canonware.com --> jasone@freebsd.org).
2000-07-18 01:38:19 +00:00
Jason Evans
390a1cd5eb Deal correctly with statically initialized condition variables in
pthread_cond_signal(), pthread_cond_broadcast(), and pthread_cond_timedwait().

Do not dump core in pthread_cond_timedwait() (due to a NULL pointer
dereference) if attempting to wait on an uninitialized condition variable.

PR:	bin/18099
2000-07-17 22:55:05 +00:00
Jason Evans
82db3da3e1 Reshuffle the SEE ALSO section.
Prompted by:	sheldonh
2000-07-17 22:33:32 +00:00
Jason Evans
e21fa6847e Remove DEBUG_FLAGS=-g3, which never should have been committed. 2000-07-05 16:21:42 +00:00
Jason Evans
b79702feff Fix typo in SEE ALSO section. 2000-06-28 03:15:21 +00:00
Jason Evans
8d107d1210 If multiple threads are blocked in sigwait() for the same signal that does
not have a user-supplied signal handler, when a signal is delivered, one
thread will receive the signal, and then the code reverts to having no
signal handler for the signal.  This can leave the other sigwait()ing
threads stranded permanently if the signal is later ignored, or can result
in process termination when the process should have delivered the signal to
one of the threads in sigwait().

To fix this problem, maintain a count of sigwait()ers for each signal that
has no default signal handler.  Use the count to correctly install/uninstall
dummy signal handlers.

Reviewed by:	deischen
2000-06-27 21:30:16 +00:00
Jason Evans
314be1347b pthread_mutex_lock(), pthread_cond_trywait(), and pthread_cond_wait() are
not allowed to return EINTR, but use of pthread_suspend_np() could cause
EINTR to be returned.  To fix this, restructure pthread_suspend_np() so that
it does not interrupt a thread that is waiting on a mutex or condition, and
keep enough state around that pthread_resume_np() can fix things up
afterwards.

Reviewed by:	deischen
2000-06-14 17:17:41 +00:00
Chris Costello
d2e7a6a46f Fix a misspelling: undefied -> undefined 2000-05-27 22:02:32 +00:00
Jake Burkholder
e39756439c Back out the previous change to the queue(3) interface.
It was not discussed and should probably not happen.

Requested by:		msmith and others
2000-05-26 02:09:24 +00:00
Jake Burkholder
740a1973a6 Change the way that the queue(3) structures are declared; don't assume that
the type argument to *_HEAD and *_ENTRY is a struct.

Suggested by:	phk
Reviewed by:	phk
Approved by:	mdodd
2000-05-23 20:41:01 +00:00
Jason Evans
ccb3a748f4 Fix a memory leak. pthread_set_name_np() allocates space for a name, but
was not deallocating space for the previous name, if any.

PR:	misc/18504
2000-05-16 22:08:14 +00:00
Jason Evans
40316fa981 Fix a memory leak. pthread_set_name_np() allocates space for a name, but
_thread_gc() was not deallocating it.

PR:	misc/18504
2000-05-16 21:57:12 +00:00
Alexey Zelkin
0543309637 add MLINKS: pthread_testcancel(3) -> pthread_setcanceltype(3) 2000-05-12 09:59:44 +00:00
Bruce Evans
27010737a9 "Fixed" missing include in synopsis. POSIX.1-1996 only specifies
including <signal.h>, but that must be a bug in POSIX.1, because it
also specifies that the relevant prototype is [only] in <pthread.h>.
2000-05-11 16:13:18 +00:00
Bruce Evans
ce8973f06a Fixed misspelling of a struct tag in a function parameter type. 2000-05-11 16:03:38 +00:00
Bruce Evans
80a07932e7 Fixed missing consts for function parameters, so that the code matches
the man page and POSIX.1.  Fixed nearby misformatting.  Fixed a missing
prototype.
2000-05-11 15:57:17 +00:00
Sheldon Hearn
f167d7fb3e Fix miscellaneous mdoc macro argument limit infringements.
PR:		18465
Reported by:	Kazu TAKAMUNE <takamune@avrl.mei.co.jp>
2000-05-09 14:02:06 +00:00
Alexey Zelkin
2a53c5ec96 mdoc(7) cleanup:
. use real function names as `.Nm' macro argument in NAME section. It allows
them to appear in apropos(1) or whatis(1) output.

. replace empty lines with `.Pp' macro.

. replace hardcoded standard names with their `.St' macro equivalents.

. sort cross references in SEE ALSO section
2000-05-04 08:05:45 +00:00
Jason Evans
97f2978aa0 Add missing .El macro. 2000-05-03 08:50:43 +00:00
Jason Evans
4c089f4dff Add missing man pages. Fix various compliance bugs, mostly having to do with
error return values.  Implement pthread_mutexattr_gettype().

PR:		docs/16537, docs/17538
2000-05-02 06:51:40 +00:00
Jason Evans
98a1f447bb Add a wrapper for the sendfile() system call.
PR:		bin/17366
2000-04-27 00:59:44 +00:00
Jason Evans
e419521997 Add test to detect propagation of cancellation points within libc_r. 2000-04-26 23:25:58 +00:00
Jason Evans
be1d533999 Automated regression test harness for libc_r. Existing tests are integrated,
a new test for POSIX semaphores was added, and examples of harness usage are
included.
2000-04-24 21:07:45 +00:00
Alexey Zelkin
d8a7868820 Introduce .Lb macro to libc_r manpages. 2000-04-22 15:50:29 +00:00
Jason Evans
7e5e179982 Explicitly include sys/cdefs.h to get the definition of __strong_reference(),
rather than getting lucky due to header dependencies.
2000-03-18 22:36:46 +00:00
Daniel Eischen
1d013a86ed Fix pthread_suspend_np/pthread_resume_np. For the record, suspending a
thread waiting on an event (I/O, condvar, etc) will, when resumed using
pthread_resume_np, return with EINTR.  For example, suspending and resuming
a thread blocked on read() will not requeue the thread for the read, but
will return -1 with errno = EINTR.  If the suspended thread is in a critical
region, the thread is suspended as soon as it leaves the critical region.

Fix a bogon in pthread_kill() where a signal was being delivered twice
to threads waiting in sigwait().

Reported by (suspend/resume bug):	jdp
Reviewed by:	jasone
2000-03-15 13:59:27 +00:00
Sheldon Hearn
c6ff3a1bf7 Remove single-space hard sentence breaks. These degrade the quality
of the typeset output, tend to make diffs harder to read and provide
bad examples for new-comers to mdoc.
2000-03-02 09:14:21 +00:00
Ruslan Ermilov
a02c8fe575 Fix the installworld breakage from rev 1.9.
Submitted by:	reg
Reviewed by:	ru
Approved by:	jasone (rev 1.9)
Pointy hat to:	unfurl
2000-02-18 13:21:16 +00:00
Bill Swingle
9969b45007 fixed missing trailing \
Submitted by:	Thimble Smith <tim@mysql.com>
2000-02-18 05:31:26 +00:00
Bill Swingle
30fd3a5b2b Adds missing symlinks for pthread related manpages.
PR:		16537
Submitted by:	AnarCat <beaupran@iro.umontreal.ca>
Approved by:	jasone
2000-02-18 02:26:27 +00:00
Jason Evans
8a668b9049 For errors, return -1 and set errno to indicate the error type, rather than
returning the error directly.

For sem_post(), make sure that the correct thread is woken up.  This has
unfortunate performance implications, but is necessary for POSIX compliance.

Approved by:	jkh
2000-02-16 19:34:53 +00:00
Jason Evans
b0a1b4f809 Add man pages for the sem_*() functions.
Approved by:	jkh
2000-02-16 19:31:53 +00:00
Jason Evans
d77639f25f Use __strong_reference() instead of __weak_reference() to assure that the
weak symbols of the same name are not used.
2000-01-29 22:53:55 +00:00
Jason Evans
4ec6f67d10 Use _fcntl() (not fcntl()) inside of fcntl().
Reported by:	green
2000-01-28 22:10:27 +00:00
Jason Evans
9233c4d942 Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),
just use _foo() <-- foo().  In the case of a libpthread that doesn't do
call conversion (such as linuxthreads and our upcoming libpthread), this
is adequate.  In the case of libc_r, we still need three names, which are
now _thread_sys_foo() <-- _foo() <-- foo().

Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(),
nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo().

Remove all internal libc usage of: creat(), pause(), sleep(), system(),
tcdrain(), wait(), and waitpid().

Make thread cancellation fully POSIX-compliant.

Suggested by:	deischen
2000-01-27 23:07:25 +00:00
Jason Evans
0c5d1a3361 Fix millisecond to nanosecond conversion.
PR:		misc/16245
2000-01-22 09:15:15 +00:00
Jason Evans
beab1ec9b5 Minor *jmp() cleanups. 2000-01-20 21:53:59 +00:00
Jason Evans
120bfc9ded Add sem_*() functions. Named semaphores and process-shared semaphores
are not supported by this implementation, and the error return values
from sem_init(), sem_open(), sem_close(), and sem_unlink() reflect this.

Approved by:	jkh
2000-01-20 07:54:49 +00:00
Jason Evans
adbd6ee028 Do signal deferral for pthread_kill() as it was done in the old days.
Submitted by:	deischen
2000-01-20 04:46:52 +00:00
Jason Evans
0a3fa43c7e Implement continuations to correctly handle [sig|_]longjmp() inside of a
signal handler.  Explicitly check for jumps to anywhere other than the
current stack, since such jumps are undefined according to POSIX.

While we're at it, convert thread cancellation to use continuations, since
it's cleaner than the original cancellation code.

Avoid delivering a signal to a thread twice.  This was a pre-existing bug,
but was likely unexposed until these other changes were made.

Defer signals generated by pthread_kill() so that they can be delivered on
the appropriate stack.  deischen claims that this is unnecessary, which is
likely true, but without this change, pthread_kill() can cause undefined
priority queue states and/or PANICs in [sig|_]longjmp(), so I'm leaving
this in for now.  To compile this code out and exercise the bug, define
the _NO_UNDISPATCH cpp macro.  Defining _PTHREADS_INVARIANTS as well will
cause earlier crashes.

PR:			kern/14685
Collaboration with:	deischen
2000-01-19 07:04:50 +00:00
Daniel Eischen
7e416d8e49 Properly initialize the last active time of the initial thread. This fixes
the case that a CPU hungry main thread is prevented from being preempted
due to a negative calculation of its time slice.

Reported by:	Alexander Litvin <archer@lucky.net>
2000-01-18 11:35:25 +00:00
Jason Evans
f560c4e709 Track libc's three-tier symbol naming. libc_r must currently implement
the _libc_*() entry points and add *() weak aliases.  This will all
change for the better when libc_r becomes libpthread.
2000-01-12 09:28:58 +00:00
Daniel Eischen
3eadb69d1f Make sched_param parameter a const to comply with POSIX and SUSv2 specs.
This doesn't need to be applied to stable, because somehow -stable seems
to have gotten it right.

Reviewed by:	jasone
2000-01-10 04:14:08 +00:00
Daniel Eischen
171eec1876 Change REGENTS -> AUTHOR in the copyright.
Add $FreeBSD$.

I missed this file in a previous commit.

Pointed out by:		tg
2000-01-06 12:16:16 +00:00
Jason Evans
91e92a2d3d Don't explicitly mmap() red zones at the bottom of thread stacks (except
the initial thread).  Instead, just leave an unmapped gap between thread
stacks and make sure that the thread stacks won't grow into these gaps,
simply by limiting the size of the stacks with the 'len' argument to
mmap().  This (if I understand correctly) reduces VM overhead
considerably.

Reviewed by:	deischen
1999-12-29 15:44:59 +00:00
Daniel Eischen
1752e66d49 -Wall and minor style(9) cleanups. 1999-12-28 18:13:04 +00:00
Daniel Eischen
69186ed701 Change stack allocation algorithm to make better use of memory
(it was leaving an unused block).  Also protect the global stack
pointer from context changes while fiddling with it.
1999-12-28 18:12:07 +00:00
Daniel Eischen
8d048bba15 Don't wakeup threads when there is a process signal and no installed
handler.  Thread-to-thread signals (pthread_signal) are treated differently
than process signals; a pthread_signal can wakeup a blocked thread if
a signal handler is not installed for that signal.

Found by:	ACE tests
1999-12-28 18:08:09 +00:00
Bruce Evans
e7589db845 Fixed bitrot in synopsis. The change from "int *pshared" to "int pshared"
hadn't reached here.
1999-12-23 16:51:27 +00:00
Jason Evans
386812d440 Fix some minor POSIX/SUSv2 compliance nits.
PR:		kern/11982
1999-12-18 01:00:42 +00:00
Alexey Zelkin
ded8c91a78 Fix typos
PR:		docs/14858
Submitted by:	OKAZAKI Tetsurou <okazaki@be.to>
1999-12-17 14:48:00 +00:00
Daniel Eischen
746ff5ad85 Change to work with recent signal changes. The signal being handled is
now added to the signal mask; this test failed because it didn't allow
for this.
1999-12-17 11:46:55 +00:00
Daniel Eischen
fc8f3f5bfe Fix problems with cancellation while in critical regions.
o Cancellation flags were not getting properly set/cleared.
  o Loops waiting for internal locks were not being exited
    correctly by a cancelled thread.
  o Minor spelling (cancelation -> cancellation) and formatting
    corrections (missing tab).

Found by:	tg
Reviewed by:	jasone
1999-12-17 00:57:54 +00:00
Daniel Eischen
3dc268f4e7 Fixes for signal handling:
o Don't call signal handlers with the signal handler access lock
    held.
  o Remove pending signals before calling signal handlers.  If
    pending signals were not removed prior to handling them,
    invocation of the handler could cause the handler to be
    called more than once for the same signal.  Found by: JB
  o When SIGCHLD arrives, wake up all threads in PS_WAIT_WAIT
    (wait4).

PR:		bin/15328
Reviewed by:	jasone
1999-12-17 00:56:36 +00:00
Jason Evans
e6a5e33c6b Avoid an infinite loop if the last element of the iov array passed to
writev() has an iov_len of 0.

PR:		bin/8281
1999-12-16 22:35:40 +00:00
Daniel Eischen
70d192fd9b Make work for sigset_t change. Also modify tests to account for
recent changes to signal handling.
1999-12-05 00:48:53 +00:00
Daniel Eischen
4fc937ef8f Change signal handling to conform to POSIX specified semantics.
Before this change, a signal was delivered to each thread that
didn't have the signal masked.  Signals also improperly woke up
threads waiting on I/O.  With this change, signals are now
handled in the following way:

  o If a thread is waiting in a sigwait for the signal,
    then the thread is woken up.

  o If no threads are sigwait'ing on the signal and a
    thread is in a sigsuspend waiting for the signal,
    then the thread is woken up.

  o In the case that no threads are waiting or suspended
    on the signal, then the signal is delivered to the
    first thread we find that has the signal unmasked.

  o If no threads are waiting or suspended on the signal,
    and no threads have the signal unmasked, then the signal
    is added to the process wide pending signal set.  The
    signal will be delivered to the first thread that unmasks
    the signal.

If there is an installed signal handler, it is only invoked
if the chosen thread was not in a sigwait.

In the case that multiple threads are waiting or suspended
on a signal, or multiple threads have the signal unmasked,
we wake up/deliver the signal to the first thread we find.
The above rules still apply.

Reported by:	Scott Hess <scott@avantgo.com>
Reviewed by:	jb, jasone
1999-12-04 22:55:59 +00:00
Doug Rabson
3c085f72bb * Fix the stack allocation code so that it works for alpha. Change it
to use mmap(..., MAP_STACK, ...) on alpha too since that should work
  now.
* Add hooks to allow GDB to access the internals of pthreads without
  having to know the exact layout of struct pthread.

Reviewed by: deischen
1999-11-28 19:47:43 +00:00
Alfred Perlstein
7285bccf1a add pthread_cancel, obtained from OpenBSD.
eischen (Daniel Eischen) added wrappers to protect against cancled
threads orphaning internal resources.

the cancelability code is still a bit fuzzy but works for test
programs of my own, OpenBSD's and some examples from ORA's books.

add readdir_r to both libc and libc_r

add some 'const' attributes to function parameters

Reviewed by: eischen, jasone
1999-11-28 05:38:13 +00:00
Poul-Henning Kamp
9b962c56a4 General clean-up of socket.h and associated sources to synchronise up
with NetBSD and the Single Unix Specification v2.

This updates some structures with other, almost equivalent types and
effort is under way to get the whole more consistent.

Also removes a double definition of INET6 and some other clean-ups.

Reviewed by: green, bde, phk
Some part obtained from: NetBSD, SUSv2 specification
1999-11-24 20:49:04 +00:00
Marcel Moolenaar
616842b791 Add sigsuspend.o and sigpending.o to HIDDEN_SYSCALLS as well.
Pointed out by: jdp
1999-10-14 10:08:53 +00:00
Marcel Moolenaar
a8ce772846 Add sigprocmask to HIDDEN_SYSCALLS. This renames the syscall to
_thread_sys_sisprocmask in libc_r. This solves the undefined symbol...

Reported by: Kenneth Wayne Culver
1999-09-30 15:07:43 +00:00
Marcel Moolenaar
74562f1a2a Add the proper headers so that the SIGNOTEMPTY and SIGSETAND
macros are defined.
1999-09-30 14:51:31 +00:00
Marcel Moolenaar
3cf3c5d9dd sigset_t change (part 5 of 5)
-----------------------------

Most of the userland changes are in libc. For both the alpha
and the i386 setjmp has been changed to accomodate for the
new sigset_t. Internally, libc is mostly rewritten to use the
new syscalls. The exception is in compat-43/sigcompat.c

The POSIX thread library has also been rewritten to use the
new sigset_t. Except, that it currently only handles NSIG
signals instead of the maximum _SIG_MAXSIG. This should not
be a problem because current applications don't use any
signals higher than NSIG.

There are version bumps for the following libraries:
  libdialog
  libreadline
  libc
  libc_r
  libedit
  libftpio
  libss

These libraries either a) have one of the modified structures
visible in the interface, or b) use sigset_t internally and
may cause breakage if new binaries are used against libraries
that don't have the sigset_t change. This not an immediate
issue, but will be as soon as applications start using the
new range to its fullest.

NOTE: libncurses already had an version bump and has not been
      given one now.

NOTE: doscmd is a real casualty and has been disconnected for
      the moment. Reconnection will eventually happen after
      doscmd has been fixed. I'm aware that being the last one
      to touch it, I'm automaticly promoted to being maintainer.
      According to good taste this means that I will receive a
      badge which either will be glued or mechanically stapled,
      drilled or otherwise violently forced onto me :-)

NOTE: pcvt/vttest cannot be compiled with -traditional. The
      change cause sys/types to be included along the way which
      contains the const and volatile modifiers. I don't consider
      this a solution, but more a workaround.
1999-09-29 15:18:46 +00:00
Dmitrij Tejblum
ffd73a0043 Fix a memory leak: free the thread-specific poll_data, used in the select()
implementation.

PR:		13368
Submitted by:	Steve Bernacki, Jr. <steve@copacetic.net>
1999-08-30 15:45:42 +00:00
Daniel Eischen
3e12058d25 When checking for valid timevals in the wrapped select() and poll()
routines, don't return EINVAL but set errno to EINVAL and return -1.
Added a check in pthread_cond_timedwait for a null timespec pointer.
1999-08-30 00:02:08 +00:00
Peter Wemm
7f3dea244c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
Alfred Perlstein
89f6acf96a move sanity check of timeval struct so as not to segfault when passed
a null pointer.

Pointed out by: Thomas Gellekum <tg@ihf.rwth-aachen.de>
Reviewed by:    eivind
1999-08-20 21:06:20 +00:00
John Birrell
e4065e8294 When checking if there is a stack to free, observe the fact that it
might have been mmapped, and if so, passing the pointer to free() is
really not a good idea.

[ In the next millenium, when I've taken over the world, I'm going
  to ban 8 character tabs. You've been warned. ]
1999-08-20 12:17:09 +00:00
Ralf S. Engelschall
49b1e06a15 Fix EINVAL related descriptions. 1999-08-20 07:00:22 +00:00
Alfred Perlstein
4c263f605c time_to_sleep->tv_nsec > 1000000000
-to-
time_to_sleep->tv_nsec >= 1000000000
1999-08-19 23:18:07 +00:00
Alfred Perlstein
91518882e0 Sanity check time structures passed in, return EINVAL like the system
calls do to avoid corrupting the thread library's concept of wakeup
time.

PR:		kern/12141
Reviewed by:	deischen, eivind
1999-08-19 23:06:11 +00:00
Alfred Perlstein
c81c6baf1d handle under/overflow of time values in a more robust manner,
there may be an overflow that need to be adjusted more than once.

Pointed out by: Fabian Thylmann <fthylmann@stats.net>

Reviewed by:	eivind, jb
1999-08-19 16:49:53 +00:00
Ralf S. Engelschall
526148f2b9 Fix description of the _thread_autoinit_dummy_decl trick. 1999-08-17 09:50:21 +00:00
Chris Costello
f815187c41 Bad reference exit(2) changed to exit(3) 1999-08-14 08:05:46 +00:00
Daniel Eischen
936aa6b443 Add check for runnable threads before polling file descriptors.
Submitted by:	tegge
1999-08-12 19:34:39 +00:00
Daniel Eischen
fa7c4d5575 Add RCS IDs to those files without them.
Fix copyrights (s/REGENTS/AUTHOR).

Suggested by:	tg
Approved by:	jb
1999-08-05 12:15:30 +00:00
Daniel Eischen
8b5d18ec76 Fix thread initialization to allow for the case where stdio file
descriptors are not opened.

PR:		bin/12853
Reviewed by:	jb
1999-08-05 12:08:10 +00:00
Nik Clayton
fbc400a67a Add $Id$, to make it simpler for members of the translation teams to
track.

The $Id$ line is normally at the bottom of the main comment block in the
man page, separated from the rest of the manpage by an empty comment,
like so;

     .\"    $Id$
     .\"

If the immediately preceding comment is a @(#) format ID marker than the
the $Id$ will line up underneath it with no intervening blank lines.
Otherwise, an additional blank line is inserted.

Approved by:            bde
1999-07-12 20:50:10 +00:00
Dmitrij Tejblum
6ff19e189d Use USRSTACK (defined in <machine/vmparam.h>) to get top of the initial stack.
PTHREAD_STACK_TOP was wrong for all supported architectures.
1999-07-12 16:09:30 +00:00
Jason Evans
66da783384 Fix a couple more coding style nits. 1999-07-11 06:06:52 +00:00
Jason Evans
34582929f1 Modify previous changes to conform better to libc_r's coding style.
Always use mmap() for default-size stack allocation.  Use MAP_ANON instead
of MAP_STACK on the alpha architecture.

Reduce the amount of code executed while owning _gc_mutex during stack
allocation.
1999-07-11 05:56:37 +00:00
Jason Evans
876cc3dae0 Always use growable thread stacks on the i386. The VM_STACK kernel option
must be made default for the alpha before growable thread stacks are
enabled for the alpha.
1999-07-06 00:25:38 +00:00
Jason Evans
439cce0e4b Disable growable stacks by default, as advertised. 1999-07-05 00:38:12 +00:00
Jason Evans
ecaa6e8c9e Use growable stacks for thread stacks that are the default stack size.
Cache discarded default thread stacks for use in subsequent thread creations.

Create a red zone at the end of each stack (including the initial thread
stack), with the hope of causing a segfault if a stack overflows.

To activate these modifications, add -D_PTHREAD_GSTACK to CFLAGS in
src/lib/libc_r/Makefile.  Since the modifications depend on the VM_STACK
kernel option, I'm not sure how to safely use growable stacks by default.

Testing, as well as algorithmic and stylistic comments are welcome.
1999-07-05 00:35:19 +00:00
Dmitrij Tejblum
db06cf96d5 Defer signals, so we will not wait for SIGCHLD after it was delivered. 1999-06-29 19:57:07 +00:00
Dmitrij Tejblum
2467b7977b Fix few warnings on the alpha. 1999-06-23 15:01:22 +00:00
John Birrell
38329e8a07 Remove -DNOPOLL from the compilation flags now that there is a poll wrapper
in libc_r.

Bump the library version number (the scheduler now uses a poll syscall
instead of select).
1999-06-20 08:32:37 +00:00
John Birrell
02292f131a In the words of the author:
o The polling mechanism for I/O readiness was changed from
    select() to poll().  In additon, a wrapped version of poll()
    is now provided.

  o The wrapped select routine now converts each fd_set to a
    poll array so that the thread scheduler doesn't have to
    perform a bitwise search for selected fds each time file
    descriptors are polled for I/O readiness.

  o The thread scheduler was modified to use a new queue (_workq)
    for threads that need work.  Threads waiting for I/O readiness
    and spinblocks are added to the work queue in addition to the
    waiting queue.  This reduces the time spent forming/searching
    the array of file descriptors being polled.

  o The waiting queue (_waitingq) is now maintained in order of
    thread wakeup time.  This allows the thread scheduler to
    find the nearest wakeup time by looking at the first thread
    in the queue instead of searching the entire queue.

  o Removed file descriptor locking for select/poll routines.  An
    application should not rely on the threads library for providing
    this locking; if necessary, the application should use mutexes
    to protect selecting/polling of file descriptors.

  o Retrieve and use the kernel clock rate/resolution at startup
    instead of hardcoding the clock resolution to 10 msec (tested
    with kernel running at 1000 HZ).

  o All queues have been changed to use queue.h macros.  These
    include the queues of all threads, dead threads, and threads
    waiting for file descriptor locks.

  o Added reinitialization of the GC mutex and condition variable
    after a fork.  Also prevented reallocation of the ready queue
    after a fork.

  o Prevented the wrapped close routine from closing the thread
    kernel pipes.

  o Initialized file descriptor table for stdio entries at thread
    init.

  o Provided additional flags to indicate to what queues threads
    belong.

  o Moved TAILQ initialization for statically allocated mutex and
    condition variables to after the spinlock.

  o Added dispatching of signals to pthread_kill.  Removing the
    dispatching of signals from thread activation broke sigsuspend
    when pthread_kill was used to send a signal to a thread.

  o Temporarily set the state of a thread to PS_SUSPENDED when it
    is first created and placed in the list of threads so that it
    will not be accidentally scheduled before becoming a member
    of one of the scheduling queues.

  o Change the signal handler to queue signals to the thread kernel
    pipe if the scheduling queues are protected.  When scheduling
    queues are unprotected, signals are then dequeued and handled.

  o Ensured that all installed signal handlers block the scheduling
    signal and that the scheduling signal handler blocks all
    other signals.  This ensures that the signal handler is only
    interruptible for and by non-scheduling signals.  An atomic
    lock is used to decide which instance of the signal handler
    will handle pending signals.

  o Removed _lock_thread_list and _unlock_thread_list as they are
    no longer used to protect the thread list.

  o Added missing RCS IDs to modified files.

  o Added checks for appropriate queue membership and activity when
    adding, removing, and searching the scheduling queues.  These
    checks add very little overhead and are enabled when compiled
    with _PTHREADS_INVARIANTS defined.  Suggested and implemented
    by Tor Egge with some modification by me.

  o Close a race condition in uthread_close.  (Tor Egge)

  o Protect the scheduling queues while modifying them in
    pthread_cond_signal and _thread_fd_unlock.  (Tor Egge)

  o Ensure that when a thread gets a mutex, the mutex is on that
    threads list of owned mutexes.  (Tor Egge)

  o Set the kernel-in-scheduler flag in _thread_kern_sched_state
    and _thread_kern_sched_state_unlock to prevent a scheduling
    signal from calling the scheduler again.  (Tor Egge)

  o Don't use TAILQ_FOREACH macro while searching the waiting
    queue for threads in a sigwait state, because a change of
    state destroys the TAILQ link.  It is actually safe to do
    so, though, because once a sigwaiting thread is found, the
    loop ends and the function returns.  (Tor Egge)

  o When dispatching signals to threads, make the thread inherit
    the signal deferral flag of the currently running thread.
    (Tor Egge)

Submitted by: Daniel Eischen <eischen@vigrid.com> and
              Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
John Birrell
994d9b67a5 Added a missing comma to the static condition variable initialisation
definition.

Submitted by: David Leonard <David.Leonard@csee.uq.edu.au>, an OpenBSD guy.
1999-05-24 07:22:55 +00:00
John Birrell
eb9dc34d8b Fix a problem with static initialisation of mutexes and condition
variables.

Submitted by: Dan Eischen <eischen@vigrid.com>
1999-05-23 10:55:33 +00:00
John Birrell
65d33b21e6 Ensure that an existing thread gets it's state set to PS_DEAD to
prevent being rescheduled.

Submitted by: Dan Eischen <eischen@vigrid.com>
1999-05-16 05:25:37 +00:00
Nate Williams
283f072c78 - Fixed bug where we NULL'd before we freed the data causing a memory leak.
Submitted by:	 Ralf S. Engelschall
Obtained from:	PR i386/11713
1999-05-14 21:36:16 +00:00
Alexander Langer
b2e3e4382d Removed extraneous comma in xrefs. 1999-05-14 21:03:23 +00:00
Alexander Langer
c2a44ea9e0 Added missing comma in xrefs. 1999-05-14 21:03:11 +00:00
John Birrell
608fa2c9e7 Mutex test program.
Submitted by: Daniel Eischen <eischen@vigrid.com>
1999-05-09 07:55:24 +00:00
John Birrell
33859c8093 Add mutex test program. 1999-05-09 07:50:31 +00:00
Jason Evans
c578efe575 Back out patch for cond_timedwait() bug from -current, since other changes
have made the patch obsolete, as pointed out by Daniel Eischen
<eischen@vigrid.com>.

PR:		bin/8872
1999-05-08 07:50:05 +00:00
Jason Evans
a1aefaec27 Apply patch included in bin/8872. This fixes a bug that occurs when
pthread_cond_timedwait() times out.

PR:		bin/8872
Submitted by:	Jason Evans <jasone@canonware.com>
Reviewed by:	David Schwartz <davids@webmaster.com>
1999-05-07 07:59:44 +00:00
John Birrell
58a7cc5d1b [ The author's description... ]
o Runnable threads are now maintained in priority queues.  The
    implementation requires two things:

      1.) The priority queues must be protected during insertion
          and removal of threads.  Since the kernel scheduler
          must modify the priority queues, a spinlock for
          protection cannot be used.   The functions
          _thread_kern_sched_defer() and _thread_kern_sched_undefer()
          were added to {un}defer kernel scheduler activation.

      2.) A thread (active) priority change can be performed only
          when the thread is removed from the priority queue.  The
          implementation uses a threads active priority when
          inserting it into the queue.

    A by-product is that thread switches are much faster.  A
    separate queue is used for waiting and/or blocked threads,
    and it is searched at most 2 times in the kernel scheduler
    when there are active threads.  It should be possible to
    reduce this to once by combining polling of threads waiting
    on I/O with the loop that looks for timed out threads and
    the minimum timeout value.

  o Functions to defer kernel scheduler activation were added.  These
    are _thread_kern_sched_defer() and _thread_kern_sched_undefer()
    and may be called recursively.  These routines do not block the
    scheduling signal, but latch its occurrence.  The signal handler
    will not call the kernel scheduler when the running thread has
    deferred scheduling, but it will be called when running thread
    undefers scheduling.

  o Added support for _POSIX_THREAD_PRIORITY_SCHEDULING.  All the
    POSIX routines required by this should now be implemented.
    One note, SCHED_OTHER, SCHED_FIFO, and SCHED_RR are required
    to be defined by including pthread.h.  These defines are currently
    in sched.h.  I modified pthread.h to include sched.h but don't
    know if this is the proper thing to do.

  o Added support for priority protection and inheritence mutexes.
    This allows definition of _POSIX_THREAD_PRIO_PROTECT and
    _POSIX_THREAD_PRIO_INHERIT.

  o Added additional error checks required by POSIX for mutexes and
    condition variables.

  o Provided a wrapper for sigpending which is marked as a hidden
    syscall.

  o Added a non-portable function as a debugging aid to allow an
    application to monitor thread context switches.  An application
    can install a routine that gets called everytime a thread
    (explicitly created by the application) gets context switched.
    The routine gets passed the pthread IDs of the threads that are
    being switched in and out.

Submitted by: Dan Eischen <eischen@vigrid.com>

Changes by me:

  o Added a PS_SPINBLOCK state to deal with the priority inversion
    problem most often (I think) seen by threads calling malloc/free/realloc.

  o Dispatch signals to the running thread directly rather than at a
    context switch to avoid the situation where the switch never occurs.
1999-03-23 05:07:56 +00:00
Alexander Langer
da69a97ff0 Typo fix (set --> get).
Obtained from:	OpenBSD (David Leonard)
1999-03-22 23:13:37 +00:00
Bruce Evans
dcb964fa34 Fixed bitrot in synopsis (some const poisoning hadn't reached here). 1999-03-05 18:43:00 +00:00
John Birrell
0883c4c31b Increase the size of private thread flags so that the test for a
thread trying to call pthread_exit() from a cleanup handler actually
works.

Submitted by: David Leonard <david.leonard@csee.uq.edu.au> OpenBSD
1999-01-15 00:21:03 +00:00
Warner Losh
d0c4729014 Fix a minor security problem in libc_r.
Submitted by: Alexandre Snarskii <snar@paranoia.ru>
Approved by: John Birrell
Reminded me that I'd been sitting on this too long: snar@paranoia.ru
1999-01-11 00:02:37 +00:00
John Birrell
7897c2a418 Don't hide mknod, it doesn't need a wrapper and never has had one. 1998-12-10 20:27:52 +00:00
Eivind Eklund
07bab7c6a4 Add support for pthread_mutexattr_settype(). As a side effect of
testing this, fix MUTEX_TYPE_COUNTING_FAST.  Recursive locks now work.
1998-11-28 23:52:58 +00:00
John Birrell
4896148e72 Interrupt threads waiting in select etc.
Submitted by: Alec Wolman <wolman@cs.washington.edu>
1998-11-15 10:01:34 +00:00
John Birrell
e7b7b3f3de Close a window between unlocking a spinlock and changing the thread state. 1998-11-15 09:58:26 +00:00
Dmitrij Tejblum
171a7528a8 Don't call pthread_mutex_lock with _SPINLOCK held.
Made pthread_cond_wait() more similar to pthread_cond_timedwait().

PR:		8375
1998-11-06 21:04:02 +00:00
Dmitrij Tejblum
4b12016bab Fix some bugs in pthread scheduler:
make pthread_yield() more reliable,
  threads always (I hope) preempted at least every 0.1 sec, as intended.

PR:		bin/7744
Submitted by:	"Richard Seaman, Jr." <dick@tar.com>
1998-10-09 19:01:30 +00:00
Dmitrij Tejblum
60abf62bfa Debug when an environment variable set, no when it is unset. 1998-09-30 19:17:51 +00:00
John Birrell
cffdbf7096 Revise test code for sigwait and add test code for sigsuspend.
Submitted by: Daniel M. Eischen <eischen@vigrid.com>
1998-09-30 07:14:02 +00:00
John Birrell
058716097d Revise test code for sigwait and add test code for sigsuspend.
Submitted by: Daniel M. Eischen <eischen@vigrid.com>
1998-09-30 07:08:09 +00:00
John Birrell
f51ea46d24 Fix a comment. 1998-09-30 06:42:29 +00:00
John Birrell
d3bb66886d Cosmetic cleansing. This code requires extra work to keep the garbage
collector thread running after a fork.
1998-09-30 06:41:16 +00:00
John Birrell
dc3a8b52c0 Move the cleanup code that frees memory allocated for a dead thread from
the thread kernel into a garbage collector thread which is started when
the fisrt thread is created (other than the initial thread). This
removes the window of opportunity where a context switch will cause a
thread that has locked the malloc spinlock, to enter the thread kernel,
find there is a dead thread and try to free memory, therefore trying
to lock the malloc spinlock against itself.

The garbage collector thread acts just like any other thread, so
instead of having a spinlock to control accesses to the dead thread
list, it uses a mutex and a condition variable so that it can happily
wait to be signalled when a thread exists.
1998-09-30 06:36:56 +00:00
John Birrell
05f3e91279 Use snprintf instead of sprintf to avoid long source file paths from
launching an application into space when someone tries to debug it.

The dead thread list now has it's own link pointer, so use that when
reporting the grateful dead.
1998-09-30 06:29:54 +00:00
John Birrell
54059e9f3f Implementation of an additional state called SIGWAIT (with the previous
one renamed to SIGSUSPEND) to fix sigwait().

Submitted by: Daniel M. Eischen <eischen@vigrid.com>
1998-09-30 06:27:31 +00:00
John Birrell
92ce833722 NULL a pointer after it is freed to avoid trying to free it again. 1998-09-30 06:24:57 +00:00
John Birrell
a247f83316 - Fix the debug macros.
-  Add support of a thread being listed in the dead thread list as well
   as the thread list.
-  Add a new thread state to make sigwait work properly. (Submitted by
   Daniel M. Eischen <eischen@vigrid.com>)
-  Add global variable for the garbage collector mutex and condition
   variable.
-  Delete a couple of prototypes that are no longer required.
-  Add a prototype for the garbage collector thread.
1998-09-30 06:22:07 +00:00
Doug Rabson
1624bd7303 Change to a code sequence which is more likely to work on SMP systems.
Now all I need is an alpha SMP box to port FreeBSD to :-)
1998-09-16 09:27:05 +00:00
Dmitrij Tejblum
8ab6008b79 Don't clobber errno if we are not going to fail. 1998-09-13 15:33:42 +00:00
Dmitrij Tejblum
99c167bba4 Don't lock newfd if it is not opened.
PR:		5961
1998-09-13 12:48:47 +00:00
Dmitrij Tejblum
deb9688ae1 In libc_r, rename vfork syscall to _thread_sys_vfork and make vfork an alias
to fork. It is difficult to do real vfork in libc_r, since almost every
operation with file descriptsor changes _thread_fd_table and friends.

popen(3) works much better with this change.
1998-09-12 22:03:20 +00:00
Dmitrij Tejblum
f0f066ec83 Fixed bug, caused threads to wait for locks which nobody hold.
Fixed sign extension bug, caused undefined behavior if FILE live in stack.
1998-09-09 16:50:33 +00:00
Alexander Langer
cecc7b0974 Removed unused variables. 1998-09-07 21:55:01 +00:00
Alexander Langer
e66632a35c Removed some variable initializations which were unnecessary and divergent
from style(9).
1998-09-07 21:07:59 +00:00
Alexander Langer
23424a1f9a -Wall clean. 1998-09-07 19:23:55 +00:00
Alexander Langer
c0e366326f Implement pthread read/write locks as defined by Version 2 of the Single
UNIX Specification.

As with our standard mutexes, process shared locks are not supported at
this time.
1998-09-07 19:01:43 +00:00
Wolfram Schneider
acd8019083 Sort cross references. 1998-08-31 16:41:09 +00:00
John Birrell
5f867deba5 Don't automatically restart syscalls for the signals that the thread
kernel needs.
1998-08-26 20:55:31 +00:00
John Birrell
353a159590 Back out most of the last commit. It created problems with sigpause. 1998-08-26 20:50:42 +00:00
John Birrell
4591e62dc7 Test program for sigwait.
Submitted by: Daniel M. Eischen <eischen@vigrid.com>
1998-08-25 12:35:16 +00:00
John Birrell
ad8f637466 Add support for building test programs. 1998-08-25 12:33:22 +00:00
John Birrell
42f37683ee Fix for sigwait problem.
Submitted by: Daniel M. Eischen <eischen@vigrid.com>
PR:           misc/7039
1998-08-25 11:19:14 +00:00
John Polstra
d89bd1ac0f Add missing initialization of the length variable passed to
getsockopt().  Use a separate variable for clarity, instead of
overloading an unrelated variable.
1998-08-12 20:29:29 +00:00
John Birrell
bbf157fac4 Add extra initialisation code that is required for processes that
are started instead of init (pid = 1). This allows an embedded
implementation quite like VxWorks, with (possibly) a single threaded
program running instead of init. The neat thing is that the same threaded
process can run in a multi-user workstation environment too.
1998-08-10 01:24:22 +00:00
Bruce Evans
30b854394a Changed prototype in synopsis to match prototype in <pthread.h>. 1998-08-03 16:54:51 +00:00
Alexander Langer
8ac3b85e63 The pthreads standard has been published. Change:
...is expected to conform to IEEE (``POSIX'') Std 1003.1c when it is
   published.
to:
   ...conforms to ISO/IEC 9945-1 ANSI/IEEE (``POSIX'') Std 1003.1 Second
   Edition 1996-07-12.

Discussed with:	jb
1998-08-03 00:58:37 +00:00
Alexander Langer
b4ff1b7295 A style fix for my previous commit. 1998-08-02 23:07:25 +00:00
Alexander Langer
27aa2e8958 Fixed a race condition during the first lock/trylock of a statically
initialized mutex.  Statically initialized mutexes are actually
initialized at first use (pthread_mutex_lock/pthread_mutex_trylock).
To prevent concurrent initialization by multiple threads, all
static initializations are now serialized by a spinlock.

Reviewed by:	jb
1998-08-02 17:04:25 +00:00
Poul-Henning Kamp
1fbdc08dfe I've put together man pages for the pthread_cleanup, pthread_cond, and
pthread_mutex routines. I've also tweaked pthread_create.3 to point to
pthread_cleanup_push(3) and pthread_cleanup_pop(3).

PR:		7450
Submitted by:	Brian Cully <shmit@kublai.com>
1998-07-31 09:09:19 +00:00
Bruce Evans
bcc58f6898 Fixed a printf format error. Didn't fix assumption that sigset_t is
integral.
1998-06-30 18:00:11 +00:00
John Birrell
ff09ba5fbb Add the missing {} that caused the function to return ESRCH if it
had to wait for the thread to exit and if the caller didn't want the
thread exit status.
1998-06-25 00:04:21 +00:00
John Birrell
b9148b8a3e Don't allow a SIGCHLD to wake up a thread if the process has the default
signal handler installed for SIGCHLD. The ACE MT_SOCK_Test was hanging
as the result of being interrupted when it didn't expect to be.
1998-06-17 22:29:12 +00:00
John Birrell
d989fc8faa If a thread is waiting on a child process to complete, the SIGCHLD
signal can arrive before the thread is woken from it's wait4. In this
case, don't return an EINTR, just set the thread state to running and
the wait4 wrapper will loop and get the exit status of the process.
1998-06-17 03:53:16 +00:00
Peter Wemm
02a93d74e0 Don't compile in the use of poll() when building libc_r. This isn't
so much a "fix", rather a bandaid to buy time to fix it properly
within the thread engine.
1998-06-14 11:25:46 +00:00
John Birrell
597035b4db If a short write, only loop if no error. 1998-06-14 09:36:14 +00:00
John Birrell
0b99d9d8ac Add poll to the list of hidden syscalls so that it gets renamed. This
propagates a bug (that there is no poll wrapper in libc_r), but it
prevents GNU configure scripts from trying to use it in preference
to select. libc_r really needs to change it's wait interface to use
poll instead of select because poll is more a superset of select that
the other way around.

This should allow the Roxen web server to work out-of-the-box. It's
configuration intercae is kinda neat. The code isn't. Shiver. 8-)
1998-06-12 02:21:27 +00:00
John Birrell
06ca87e9f7 Update the caller's descriptor masks even if there are none ready for
I/O for those applications that don't believe the return value of zero as
meaning that THERE ARE *NO* DESCRIPTORS READY.
1998-06-12 02:17:18 +00:00
John Birrell
8eb25828ad Check the access mode in the flags before waiting on a read or a write
that might never be possible if the file was not opened in the corrent
mode. This prevents a hang for bad programs. Why do people code like that?
1998-06-10 22:28:45 +00:00
John Birrell
aef774b0d5 Remove SA_RESTART from the signal dispatch in user-space since this
seems to be tripping up a lot of applications.
1998-06-10 22:25:18 +00:00
John Birrell
3c165ef7b7 When doing a F_SETFL, read the flags back so that the ones stored
in the file descriptor table are exactly what the kernel knows subject
to the O_NONBLOCK flag being requested by the user.
1998-06-10 22:24:12 +00:00
John Birrell
627961e45f Add a commented out CFLAGS entry that can be uncommented to compile thread
lock debug into libc_r. I don't know if this is the best place to document
this, but at least it is recorded somewhere. 8-)
1998-06-09 23:25:13 +00:00
John Birrell
ddc8afd422 Implement compile time debug support instead of tracking file name and
line number every time a file descriptor is locked.

This looks like a big change but it isn't. It should reduce the size
of libc_r and make it run slightly faster.
1998-06-09 23:21:05 +00:00
John Birrell
a675022188 Add compile time debug instead of doing this all the time. Reduce the
time that a thread keeps the file descriptor table locked. In particular,
perform malloc/free calls outside the lock and handle the situation
where two threads can race to initialise the table entry for the same
file descriptor.
1998-06-09 23:16:53 +00:00
John Birrell
3411c10600 Add support for compile time debug. This is enabled if libc_r is built
with -D_LOCK_DEBUG. This adds the file name and line number to each lock
call and these are stored in the spinlock structure. When using debug
mode, the lock function will check if the thread is trying to lock
something it has already locked. This is not supposed to happen because
the lock will be freed too early.

Without lock debug, libc_r should be smaller and slightly faster.
1998-06-09 23:13:10 +00:00
John Birrell
74ebed9424 POSIX says that pthread_exit() is not allowed to be called from a
cleanup destructor, so trap this case to prevent me from being being
burnt again by applications that try to do this. With this change, an
application (like one using a mis-configured ACE) will exit the process
after displaying a message quoting the POSIX section that the application
has violated.
1998-06-09 23:08:41 +00:00
John Birrell
27949f44dc Add compile time thread lock debug support.
Add a thread specific flag to trap the case where pthread_exit() is
called from a destructor in violation of the Posix standard.
1998-06-09 23:02:43 +00:00
John Birrell
7d24d0302f Delete the atomic unlock function since it is no longer required.
Simplify the atomic lock to just write a value of 1 to the lock instead
of taking the value passed by the caller (which just confused things).
1998-06-09 08:25:41 +00:00
John Birrell
3dcb4f7556 Atomic lock asm code for the alpha version of libc_r. 1998-06-09 08:21:55 +00:00
John Birrell
2d8a580416 Add a warning message for a thread locking against itself. This is
not supposed to happen, but I have seen bogus g++ code that causes
it.
1998-06-06 07:27:06 +00:00
John Birrell
c6831395f4 Simplify the handling of thread specific data. Only track if a key
is allocated or not, rather than keeping a count and attempting to
know it it is in-use. POSIX says that once a key is deleted, using the
key again results in undefined behaviour.
1998-06-06 07:24:24 +00:00
John Birrell
c359f976b4 Re-design the thread specific key structure. 1998-06-06 07:20:23 +00:00
John Birrell
717d1611f4 I got the last commit back to front. 1998-06-06 07:02:27 +00:00
John Birrell
756534d117 Fix the signal behaviour for internal states which set the thread
state to running despite the SA_RESTART flag which is really just for
syscalls.
1998-06-05 23:31:55 +00:00
John Birrell
fca35cd32f I shouldn't do things early in the morning.
I shouldn't do things early in the morning.
[...]
I shouldn't do things early in the morning.
1998-06-01 02:14:34 +00:00
John Birrell
23c82db7a3 send and recv are wrappered in libc, so they shouldn't appear here. 1998-06-01 02:12:15 +00:00
John Birrell
8680cc3c47 Remove some syscalls that should have been renamed (libc_r doesn't need
to wrapper them) and add a couple that should have been there.
1998-05-31 23:53:50 +00:00
John Birrell
382306949d Add some missing syscall wrappers. 1998-05-31 23:48:30 +00:00
John Birrell
5d359b97bb Remove some stale code.
Pointed out by: Amancio
1998-05-31 23:47:06 +00:00
John Birrell
d972680a31 Don't restart a syscall when a SIGCHLD is received by a thread waiting
on a child process.
1998-05-31 23:46:01 +00:00
John Birrell
01029f8f17 Make a copy of the caller's iovec array, mallocing if necessary,
and modify that if the writev() syscall does not completely write
all bytes in a single call.
1998-05-27 00:44:58 +00:00
John Birrell
b46dfe97ae Remove error check from call to set the file descriptor to non-blocking
instead of explicitly ignoring some errors. This allows for the case
where a device is naturally non-blocking.
1998-05-27 00:41:22 +00:00
John Birrell
e5a8a007e1 When doing a blocking write, keep looping until all the bytes are
written without returning to the caller. This only occurs on pipes
where either the number of bytes written is greater than the pipe
buffer or if there is insufficient space in the pipe buffer because the
reader is reading slower than the writer is writing.
1998-05-25 21:45:52 +00:00
John Birrell
9839f9695a Treat the lock value as volatile. 1998-05-05 21:47:58 +00:00
James Raynard
c52c933ddd Typo fixes 1998-05-03 22:59:47 +00:00
John Birrell
b1ad8d9155 Cleanup in the child, not the parent.
Submitted by: Tor Egge <Tor.Egge@idi.ntnu.no>
1998-05-02 03:42:20 +00:00
John Birrell
96efcebdfc Fix the incremental priority increment.
PR: bin/6467 Marino Ladavac <lada@pc8811.gud.siemens.at>
1998-04-30 21:50:29 +00:00
John Birrell
7bb870ac66 Change the name of this source file so that libc_r builds it instead
of the one in libc that contains the weak symbol for __error. FreeBSD's
make accumulates paths to the point that it can find *anything*, possibly
including the car keys.
1998-04-30 09:04:10 +00:00
John Birrell
ccd1da1333 Add spinlock. 1998-04-29 11:03:34 +00:00
John Birrell
4a027d50c7 Change signal model to match POSIX (i.e. one set of signal handlers
for the process, not a separate set for each thread). By default, the
process now only has signal handlers installed for SIGVTALRM, SIGINFO
and SIGCHLD. The thread kernel signal handler is installed for other
signals on demand. This means that SIG_IGN and SIG_DFL processing is now
left to the kernel, not the thread kernel.

Change the signal dispatch to no longer use a signal thread, and
call the signal handler using the stack of the thread that has the
signal pending.

Change the atomic lock method to use test-and-set asm code with
a yield if blocked. This introduces separate locks for each type
of object instead of blocking signals to prevent a context
switch. It was this blocking of signals that caused the performance
degradation the people have noted.

This is a *big* change!
1998-04-29 09:59:34 +00:00
John Birrell
312e185f9c Don't need wrappers for longjmp/setjmp anymore. 1998-04-29 09:40:51 +00:00
John Birrell
32664a7064 Remove empty files that were renamed some time ago. 1998-04-29 09:39:34 +00:00
John Birrell
1ce8c4dc49 Atomic lock source. 1998-04-29 09:36:03 +00:00
John Birrell
af139b98d4 Allow a thread dump to report the thread's sigmask when in the
PS_SIGWAIT state.
1998-04-17 09:39:37 +00:00
John Birrell
334fa8f215 When in PS_SIGWAIT state, still call signal handlers and set errno
to EINTR.
1998-04-17 09:37:41 +00:00
John Birrell
d60f0fa60d Change the FILE locking to be by FILE, not by the underlying fd as
it was. Add a FILE_WAIT state and queue threads waiting for a FILE
lock. Start using the sys/queue.h macros instead of the way that MIT
pthreads did it.

Add a thread name to the private thread structure and a non-POSIX
function to set this. This helps (me at least) when sending a SIGINFO
to a threaded process to get a /tmp/uthread.dump to see what the
<expletive deleted> threads are doing this time. It is nice to be
able to recognise (yes, I spell that with an 's' too) which threads
are which.
1998-04-11 07:47:22 +00:00
John Birrell
883674371e Enable static initialisation of mutexes and condition variables. 1998-04-04 11:33:01 +00:00
John Birrell
f9c7be5357 Rename static initializer defines for opaque structures so that the
POSIX specified names can be declared in pthread.h.
1998-04-04 10:58:12 +00:00
John Birrell
377aa2cbb6 Move the magic field initialisation to a place when it is more magic. 1998-04-04 07:27:29 +00:00
John Birrell
ed92686917 Add a magic field to the pthread structure to help recognize valid
threads from invalid ones. The pthread structure is opaque to the user
so this change does not cause any incompatibilities.

Hopefully this change will help code that was written for draft 4
fail gracefully if the programmer ignores the compiler warning about
the change in the level of indirection for the argument passed to
pthread_detach(). I got burnt, so I fixed then (expletive deleted)
thing.

These functions comply with the revised standard. That should shut
Terry up!
1998-04-03 09:31:15 +00:00
John Birrell
4d2c1d2306 This function compiles with the standard, so say so. 1998-04-03 09:12:19 +00:00
John Birrell
bb8a420424 This function compiles with the standard, so say so.
Add a note about not touching errno and warn about previous drafts
of the standard which changed the level of indirection to the thread
argument. POSIX had a bit of trouble deciding what to do. So anyone
coding to both draft 4 and draft 10 (the final draft) will get burnt
by this function. I did. Grrr.
1998-04-03 09:11:15 +00:00
Peter Dufault
8a6472b723 Finish _POSIX_PRIORITY_SCHEDULING. Needs P1003_1B and
_KPOSIX_PRIORITY_SCHEDULING options to work.  Changes:

Change all "posix4" to "p1003_1b".  Misnamed files are left
as "posix4" until I'm told if I can simply delete them and add
new ones;

Add _POSIX_PRIORITY_SCHEDULING system calls for FreeBSD and Linux;

Add man pages for _POSIX_PRIORITY_SCHEDULING system calls;

Add options to LINT;

Minor fixes to P1003_1B code during testing.
1998-03-28 11:51:01 +00:00
Bruce Evans
5c7e14e4fb Fixed a function arg type in the synopsis. 1998-03-23 13:07:17 +00:00
John Birrell
0122d62264 Fix a problem of indirection unblocking signals that would have caused
signals to be unblocked even if they were already blocked when entering
the function.

Pointed out by: bde
1998-03-22 04:13:23 +00:00
John Birrell
9dbdb44326 When forking a process, only the running thread gets to live. All
other threads never see the light of day and if they leave things
locked, blame POSIX.
1998-03-09 06:54:50 +00:00
John Birrell
96ef575882 Add lib/libc/include as an directory to search for header files.
Change MACHINE references to MACHINE_ARCH.

Declare the names of the syscalls that need to be renamed to allow
for the functions that libc_r provides replacements for. This list
used to be in lib/libc/sys/Makefile.inc, but has been moved here
to keep that makefile tidy and remove the temptation for people to
add things to the list without adding a libc_r replacement function.
1998-03-09 05:09:43 +00:00
John Birrell
03a9d2d7c8 Add FreeBSD/Alpha code to initialise a jmpbuf for a created thread.
Change a bunch of __alpha references to __alpha__.
1998-03-09 04:46:26 +00:00
John Birrell
08d6f1187e Add sched_yield() witch is the draft 10 equivalent of pthread_yield()
from draft 4. Move some of the schedule definitions to sched.h which
is a POSIX header.
1998-03-08 02:37:27 +00:00
Julian Elischer
f5295b34ac Fixes from Jeremy Allison and Terry Lambert for pthreads:
specifically:
uthread_accept.c: Fix for inherited socket not getting correct entry in
                  pthread flags.
uthread_create.c: Fix to allow pthread_t pointer return to be null if
                  caller doesn't care about return.
uthread_fd.c: Fix for return codes to be placed into correct errno.
uthread_init.c: Changes to make gcc-2.8 thread aware for exception stack
                frames (WARNING: This is #ifdef'ed out by default and is
		different from the Cygnus egcs fix).
uthread_ioctl.c: Fix for blocking/non-blocking ioctl.
uthread_kern.c: Signal handling fixes (only one case left to fix,
                that of an externally sent SIGSEGV and friends -
		a fairly unusual case).
uthread_write.c: Fix for lock of fd - ask for write lock, not read/write.
uthread_writev.c: Fix for lock of fd - ask for write lock, not read/write.

Pthreads now works well enough to run the LDAP and ACAPD(with the gcc 2.8 fix)
sample implementations.
1998-02-13 01:27:34 +00:00
Julian Elischer
eb45f34378 slight cleanup in handling sockets and file descriptors.
Same fix already applied to other types of fds. This one was apparently missed.
1998-02-05 21:16:52 +00:00
Alexander Langer
372787c102 Changed pthread_detach to conform to POSIX, i.e. the single argument
provided is of type pthread_t instead of pthread_t *.

PR:		4320

Return EINVAL instead of ESRCH if attempting to detach an already
detached thread.
1997-12-25 05:07:20 +00:00
Alexander Langer
09bb0da60c Modify the return values to comply with POSIX. Previously these
functions would return -1 and set errno to indicate the specific error.
POSIX requires that the functions return the error code as the return
value of the function instead.
1997-11-25 01:29:16 +00:00
Alexander Langer
3234f7c1cc Added missing source file uthread_sigwait.c.
Submitted by:	Daniel M. Eischen <deischen@iworks.InterWorks.org>
1997-11-24 23:04:29 +00:00
Alexander Langer
666dfc8237 Correct the return value from pthread_cond_timedwait when a timeout
occurs (was EAGAIN, is now ETIMEDOUT).

Submitted by:	Daniel M. Eischen <deischen@iworks.InterWorks.org>
1997-11-23 22:58:26 +00:00
John Birrell
f4084c0544 Bring back nanosleep from the cold.
The addition of the nanosleep syscall was correctly added to
libc/sys/Makefile so that it is renamed as _thread_sys_nanosleep().
This syscall is one of those that libc_r has to re-implement because
the only behaviour is to block the process. So libc_r just ignores the
fact that a nanosleep syscall exists and goes its own way - as it has
done all along .... and now it does again. And now a simple program
can sleep again. Phew.
1997-06-04 13:03:12 +00:00
Alexander Langer
9c49eac672 Fixed overallocation of _thread_fd_table.
PR:		3494
Submitted by:	Steve Bauer <sbauer@rock.sdsmt.edu>
1997-05-13 23:54:22 +00:00
Peter Wemm
a8320cdfe5 Add const in the thread version of nanosleep()'s args 1997-05-12 10:02:18 +00:00
Peter Wemm
757d77dcf5 remove prototype for nanosleep(), it's visible in unistd.h now. 1997-05-12 10:00:46 +00:00