Commit graph

145 commits

Author SHA1 Message Date
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