Commit Graph

640 Commits

Author SHA1 Message Date
ad
de2138164c Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
2007-03-02 18:53:51 +00:00
ad
dba14ef0a0 Don't grab the state lock to check for cancellation around condition
variables, as _lwp_wakeup/lwp_park provide the necessary barrier.
2007-03-02 17:47:40 +00:00
ad
dc39f9ec83 pthread_detach: acquire the join lock before changing pt_flags. 2007-03-02 17:40:55 +00:00
ad
1bcb6087a6 On x86, issue the pause instruction while spinning. 2007-03-02 17:34:21 +00:00
ad
1296e8508f - Put detached & exiting threads on the tail of the deadqueue, not head.
- Don't forget to set PT_FLAG_DETACHED.
2007-02-21 22:31:38 +00:00
ad
dacd4bd9ca Minor optimisation to previous: only check for continued existence of
the thread if it was detached.
2007-02-21 22:25:57 +00:00
yamt
4cdc2ed889 fix a race between pthread_exit and pthread_create.
inefficient, but better than crashing.
2007-02-15 15:39:33 +00:00
ad
3247035dcc Cast the return value of _lwp_unpark_all(), just in case. 2007-02-09 23:53:24 +00:00
ad
a21c37097e Bump libpthread & libpthread_dbg minor versions so that an old SA copy
gets kept in the file system. Requested by pavel.
2007-02-09 23:00:16 +00:00
ad
401499f30e Sync with kernel changes introduced by merging the newlock2 branch. 2007-02-09 22:08:48 +00:00
ad
d333bb5f2f Build without sys/sa.h present. 2007-02-06 15:24:37 +00:00
christos
858097f9a1 use __func__ instead of __FUNCTION__ which is a gcc extension. 2007-01-31 23:55:20 +00:00
christos
bbc680871a Add another volatile, mentioned in current-users from a cross-build on amd64. 2007-01-22 15:06:31 +00:00
ad
7630e3876c pthread_create(): clear newthread->pt_sleeponq before calling _lwp_create(). 2007-01-20 20:02:36 +00:00
christos
1eb6e5fbb2 add casts to pacify lint. 2007-01-20 18:58:11 +00:00
christos
25a0745d2e remove unused variable/code. 2007-01-20 18:57:41 +00:00
christos
d1ddfe10b1 fix warning about indirect call without * 2007-01-20 18:56:30 +00:00
christos
b4634d8561 sprinkle volatile. 2007-01-20 18:00:15 +00:00
christos
1636e22df7 set warns to 4 2007-01-20 04:56:25 +00:00
christos
3ca3d0b1e7 add a missing volatile. 2007-01-20 04:56:07 +00:00
hubertf
55ac93d329 Remove more duplicate #includes, and a few spurious whitespaces at EOL
From Slava Semushin <slava.semushin@gmail.com>
2007-01-17 23:24:22 +00:00
ad
8e51dbdc7e For 1:1 threads: __strong_alias(__libc_thr_yield,_sys_sched_yield) 2007-01-16 07:09:17 +00:00
ad
b8daad9836 Fix a race between pthread_exit() and pthread_join(). 2007-01-16 05:22:55 +00:00
ad
efb1fc06e2 Fix a race between pthread_create() and pthread_exit() in the 1:1 case. 2007-01-16 04:19:02 +00:00
ad
39aa27f5ce Pass in the 'hint' argument when parking/unparking LWPs. 2007-01-16 01:35:16 +00:00
drochner
9c848e15d6 bring sched_yield() back which got lost recently 2007-01-08 20:54:42 +00:00
ad
ae979b2162 Add some items for 1:1 threads. 2006-12-25 11:36:36 +00:00
ad
ded2602507 Fix bugs with and improve upon previous. 2006-12-24 18:39:45 +00:00
ad
fe9718ac7c Add another comment. 2006-12-23 09:48:18 +00:00
ad
10058f19c8 Add a comment. 2006-12-23 05:18:56 +00:00
ad
1ac6a89b79 Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
2006-12-23 05:14:46 +00:00
ad
11b0ba9c5d pthread__debuglog_printf(): check for linebuf == NULL. 2006-12-14 20:40:57 +00:00
ad
24ae41f8f3 Set _IOLBF on stdout. 2006-12-14 20:39:04 +00:00
christos
1665d5e960 fix spelling of accommodate; from Zapher. 2006-11-24 19:46:58 +00:00
yamt
41cc94b9f0 remove unused IDLESPINS. 2006-10-03 09:37:07 +00:00
wrstuden
25b0eaef3c Close a window in which we can not notice a recently-slept-on-our
mutex thread, thus leaving a thread sleeping on an unlocked mutex.

Reviewed by myself and Christos.

Problem reported by Arne H. Juul, arnej at pvv dot ntnu dot no,
in PR 26208. This fix represents option 1 presented in the PR.
2006-08-22 21:46:09 +00:00
ross
1a70c2f1e4 Err, restore the name of pthread__switch_return_point, it is
referenced from C code.
2006-07-09 01:07:38 +00:00
ross
a228aa3de2 Revise for LP64.
Encapsulate previously copied code sections into macros.
2006-07-08 05:09:44 +00:00
ross
032dc727f7 remove unreferenced temporary label 2006-07-08 05:04:49 +00:00
chuck
f4e3e7fe3b sigtimedwait: if we collect a queued signal via pt_siglist, do not
forget to clear it out of pt_siglist, otherwise we will keep getting
it over and over again.   fixes a problem introduced in rev 1.43.

problem observed with mysqld where sending it a SIGHUP after it has
set an alarm (e.g. due to some package like rt3 using it) caused the
signal handler thread to go into a tight loop (collecting a SIGALRM
[via sigwait() in mysqld.cc] that would not go away due to the above
issue).   mysqld appears to get a SIGHUP when /etc/rc exits, so it
can go into this tight loop after a reboot (but not if you restart
it by hand).   the bad sequence is:
	/etc/rc runs:
		- starts mysqld
		- starts web server with rt3 fastcgi starts
		- fastcgi/rt3 talks to mysqld (causing it to set an alarm)
		- /etc/rc exits, SIGHUP goes to mysqld
		- mysqld catches SIGHUP, signal handler thread gets
			stuck in loop (database continues to operate, slowly).

you can also trigger the problem by sending mysqld a SIGHUP by hand after
you've caused it to set an alarm by connecting to it.
2006-06-12 16:45:14 +00:00
snj
a640fe8c43 It's "its." 2006-04-24 19:00:29 +00:00
drochner
f782e99583 There is no point in using the internal sigprocmask() to initialize
the process' signal mask -- this ends up in a no-op.
Use the system call directly instead.
(This might be done in pthread_sig.c, but for now I wanted a simple
patch which is easily tested and pulled up.)
2006-04-24 18:39:36 +00:00
cube
562d0d89a2 Instead of using hard-coded values for various registers, get them from the
current context.  Valid values can change depending on how the kernel is
setup.  i386 and amd64 happen to be setup differently.
2006-03-29 22:55:15 +00:00
christos
142b3180cb Coverity CID 882: Avoid NULL deref. 2006-03-19 23:01:03 +00:00
yamt
9f9e6a32dd - do PTHREAD_MLOCK_KLUDGE in pthread__stackid_setup, rather than callers,
so that the main thread is not different from others.
  as a side effect, fix memory leak in pthread_create on error.
- make pthread__stackid_setup return a error rather than calling err(2).
2006-02-12 11:41:53 +00:00
skrll
2b3543128f I was a bit over zealous with my last change so revert the
locked_return_point change.

Loading the instruction at locked_return_point as a return value didn't
work so well.

Thanks to uwe, cube, and dsl.
2006-01-09 22:17:16 +00:00
kleink
5af00b0b39 pthread_sigmask(): Add restrict qualifier to set, oset args. 2006-01-07 20:10:29 +00:00
uwe
6b8eb49dd6 Use PLT for PIC calls to avoid text relocs in the shared library. 2006-01-06 22:46:14 +00:00
uwe
55ad9313a6 In PIC code call setcontext(2) via PLT to avoid text reloc in the
shared library.
2006-01-04 17:44:53 +00:00
skrll
73b7bdcee7 A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:

	- Don't declare pthread__switch_away global
	- Do the PIC dance for pthread__switch_return_point and
	  pthread__locked_switch. Ideally these (and other) symbols would
	  be hidden.

Thanks to uwe@, dyoung@ and elad@ for help.

XXX sh3 is still to be done.
XXX vax does strange things.
2006-01-04 12:43:43 +00:00
uwe
ffaa72c2cc Adapt to new PIC macros that are now in <machine/asm.h>. Same binary
code is generated (still with text relocs, but eliminating them is the
next step).
2005-12-31 05:08:28 +00:00
perry
ce666bb8ce __asm__ -> __asm 2005-12-24 23:10:08 +00:00
perry
4e11af46bc Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete. 2005-12-24 21:11:15 +00:00
christos
d7e5caf4fd include libc after our own files to fix ports that have 2 assym.h's. One
in pthread and one in libc.
2005-12-13 22:07:20 +00:00
chs
3ad2320789 if mlock() fails in pthread_create(), return EAGAIN instead of
failing an assertion.
2005-10-19 02:44:45 +00:00
chs
0e67554241 starting the pthread library (ie. calling pthread__start()) before
any threads are created turned out to be not such a good idea.
there are stronger requirements on what has to work in a forked child
while a process is still single-threaded.  so take all that stuff
back out and fix the problems with single-threaded programs that
are linked with libpthread differently, by checking if the library
has been started and doing completely different stuff if it hasn't been:
 - for pthread_rwlock_timedrdlock(), just fail with EDEADLK immediately.
 - for sem_wait(), the only thing that can unlock the semaphore is a
   signal handler, so use sigsuspend() to wait for a signal.
 - for pthread_mutex_lock_slow(), just go into an infinite loop
   waiting for signals.

I also noticed that there's a "sem2" test that has never worked in its
single-threaded form.  the problem there is that a signal handler tries
to take a sem_t interlock which is already held when the signal is received.
fix this too, by adding a single-threaded case for sig_trywait() that
blocks signals instead of using the userland interlock.
2005-10-19 02:15:03 +00:00
chs
ba70e96a09 in pthread_kill() and pthread_suspend_np(), return without doing anything
if the target thread is a zombie.

in all the functions that didn't do so already, verify a pthread_t before
dereferencing it (under #ifdef ERRORCHECK, since these checks are not
mandated by the standard).

clean up some debugging stuff.
2005-10-16 00:37:52 +00:00
chs
c190c7de90 fix the interaction between sigtimedwait() and pthread_kill(),
both waking up a sleeping thread and avoiding going to sleep if
a signal is already pending.  fixes PR 30348.
2005-10-16 00:31:35 +00:00
chs
2415c56ed0 in pthread_mutex_lock_slow(), pthread_rwlock_timedrdlock() and sem_wait(),
call pthread__start() if it hasn't already been called.  this avoids
an internal assertion from the library if these routines are used
before any threads are created and they need to sleep.
fixes PR 20256, PR 24241, PR 25722, PR 26096.
2005-10-16 00:07:24 +00:00
kleink
34ef731cb3 Change the sched_*() functions to return -1 and set errno to ENOSYS
(per the standard) instead of returning ENOSYS.  Noted by Ian Zagorskih
in PR kern/30970.
2005-10-09 11:17:28 +00:00
tv
21eb6bbacb pthread_attr_getschedpolicy() wasn't setting the return buffer at all.
SCHED_OTHER happens to be 0, so this assignment to "int *" succeeds,
and becomes a no-op.

Fix by dereferencing "policy" to do the assignment, thus filling the
return buffer with 0.
2005-09-21 15:27:14 +00:00
christos
f1cc481dfe XXX: Work around libpthread's "intimate" connection with libc. 2005-09-13 02:45:38 +00:00
christos
0393abcb27 Revert part of previous; we need to merge acts.sa_mask into our pthread mask.
Thanks martin...
2005-07-26 20:16:07 +00:00
christos
9d60b1fc89 - removed bogus acts.sa_mask setting.
- unblock the signal we are currently delivering, because it might have
  been blocked if we are woken up by another thread.
2005-07-26 20:11:02 +00:00
nathanw
0774992407 Add cancellation protection to pthread_once() as per the standard; if
the once routine is cancelled, the effect on once_control is as if
pthread_once() was never called.

Bug report and fix from PR lib/30734.
2005-07-16 23:14:53 +00:00
yamt
9493e4bf43 make this compile without PTHREAD_MLOCK_KLUDGE. 2005-07-01 12:35:18 +00:00
peter
d4cc3cce89 Create links for pthread_attr_setschedparam.3
and pthread_attr_getschedparam.3 to pthread_attr.3.

From Igor Sobrado in PR/29997.
2005-06-17 18:37:24 +00:00
wiz
52e496a68e New sentence, new line. 2005-06-17 18:26:53 +00:00
wiz
27d002e8de New sentence, new line.
Break much too long line.
2005-06-17 18:23:52 +00:00
peter
a28acffec8 Don't create links to pthread_barierattr_init.3 and
pthread_barierattr_destroy.3 but to pthread_barrierattr_init.3
and pthread_barrierattr_destroy.3 (note the 2 rs in barrier).
2005-06-17 18:23:19 +00:00
peter
568accb2c0 Fix various spelling errors.
From Igor Sobrado in PR/29997.
2005-06-17 18:07:06 +00:00
thorpej
d93ab54e03 Use TOOL_GENASSYM. Part of PR toolchain/30350 2005-05-30 16:02:56 +00:00
nathanw
5f7a108732 Avoid passing along a timespec with a negative number of seconds if
the current time plus the caller-supplied time to sleep wraps the
time_t. Instead, sleep until INT_MAX.
2005-04-19 16:38:57 +00:00
matt
38b7b2fcde Merge updates to algorithms from i386 switch code. 2005-04-09 20:53:19 +00:00
matt
7fa678813d Add STACKSPACE 2005-04-09 20:50:27 +00:00
matt
e722e50c79 Rework and cleanup. Don't use REI, fake a call frame instead. 2005-04-09 20:49:02 +00:00
kleink
9cf9c2316b Add restrict qualifiers to <pthread.h> function arguments. 2005-03-21 17:55:07 +00:00
kleink
34579587e1 Include <sys/select.h> explicitly rather than relying on other headers
to do it.
2005-03-21 09:00:49 +00:00
kleink
363c26d4ba Interpose cancellation points in pollts() and pselect(), bringing us
to libc.so.12.127 and libpthread.so.0.6.
2005-03-18 11:23:44 +00:00
jwise
f579845294 Lint warning police -- don't use `//' for comments in C code. 2005-03-17 17:23:21 +00:00
kleink
ebf592f1e6 Move up the definition of __LIBC12_SOURCE__; since <poll.h> now includes
<sys/sigtypes.h> this is needed earlier.
2005-03-10 00:34:23 +00:00
nathanw
22f226cf84 Correct the order of arguments to __sigplusset() in two places to correct
the signal mask experienced by signal handlers in threaded programs.
Fixes regress/lib/libpthread/sigmask3.
2005-02-27 18:25:01 +00:00
nathanw
916de87872 Keep the kernel updated with signal action signal masks (act.sa_mask) until
threads are started, since before that the traditional signal invocation
method will be used. Fixes regress/lib/libpthread/sigmask2.
2005-02-26 20:33:06 +00:00
nathanw
1eaf7124f7 Fetch the old signal mask for the signal action whether or not we're
setting a new signal action; this makes sigaction(sig, NULL, &oact)
return a sensible value in the signal mask instead of stack trash.

Addresses PR lib/29536.

XXX the mask seen by signal handlers in a program linked with
libpthread but not yet multithreaded will not reflect masks set here.
2005-02-26 18:15:25 +00:00
christos
b35aef8d4b Default back pthread__concurrency to 1 until we fix the regression test
related to pthread_kill().
2005-02-10 23:42:37 +00:00
christos
3a610280bb If $PTHREAD_CONCURRENCY is not set, set it to ncpu 2005-02-10 02:20:49 +00:00
christos
cca9405683 Add charles' mlock fixes, protected with PTHREAD_MLOCK_KLUDGE and enabled
by default, until we come up with a real fix.
2005-02-03 17:30:33 +00:00
daniel
760b46e0e9 Document PTHREAD_CONCURRENCY, ack by wiz@. 2005-02-01 11:38:27 +00:00
nathanw
efffd0e96a pthread_rwlock_timedrdlock() and pthread_rwlock_timedwrlock():
After exiting the try-again loop, make one more test of the lock
conditions, in case it was released while a signal handler kept the
thread busy past the alarm expiration.
2005-01-09 01:57:38 +00:00
nathanw
6a562a3a84 pthread_rwlock_timedrdlock() and pthread_rwlock_timedwrlock():
Expand the test for valid values of abs_timeout to check for negative
values of tv_sec and tv_nsec.
2005-01-09 01:47:20 +00:00
mycroft
6951dd53b1 Fix a pasto. 2005-01-06 17:42:31 +00:00
mycroft
077972bfb2 Replace the even-odd test for incrementing unblockgen with a simple
blockgen!=unblockgen.  I'm not sure this is 100% correct, but it partly
alleviates a problem with multiple unblocks for the same thread getting
stacked up.
2005-01-06 17:40:22 +00:00
mycroft
75a9478818 Add some additional assertions and debugging printf()s. 2005-01-06 17:38:29 +00:00
mycroft
e890aef258 Use TIMER_RELTIME rather than the constant 0 in one place. 2005-01-06 17:34:52 +00:00
mycroft
8fa85b4a65 gettimeofday();TIMEVAL_TO_TIMESPEC(); is exactly equivalent to
clock_gettime(CLOCK_REALTIME), except the latter may have more preicison
some day.  So, use that.
2005-01-06 17:33:36 +00:00
nathanw
74718675cc Avoid passing zero-valued timespecs to timer_settime() when we want to set
a timer, as that will clear the timer instead. Pass in a safely in-the-past
value instead.
Addresses PR lib/28700.

(XXX passing in values between 0 and 1000 nanoseconds will still fail, but
 that bug needs to be fixed in timer_settime(), not here)
2004-12-29 20:47:39 +00:00
nathanw
fae5965c52 Implement pthread_attr_{set,get}schedpolicy() at the same level as the other
scheduling stuff: only handle SCHED_OTHER. Like the rest of the scheduling
stuff, this is for the benefit of code that can't be bothered to test against
_POSIX_THREAD_PRIORITY_SCHEDULING.
2004-12-29 00:59:57 +00:00
wiz
c53d75fdd8 Grammar improvements. 2004-12-15 16:37:58 +00:00
wiz
dd4b29f9a3 Fix typo in comment. 2004-12-15 16:29:53 +00:00
yamt
e19f3f9976 document sched_yield. 2004-12-14 01:47:13 +00:00
nathanw
480a2816f2 Add #defines to make use of libc stubs for pthread_cond_wait() and
pthread_cond_timedwait().

XXX as noted in the comments, in the situations where these are
useful, they should never be called in a single-threaded
process. Perhaps they should die rather than return 0.

Addresses xsrc/28630.
2004-12-13 03:10:52 +00:00
nathanw
cb9ebec1e2 Correctly return ETIMEDOUT when the absolute time is in the past, in
the nonthreaded case. Fixes, and fix from, PR lib/25961.
2004-12-10 17:11:53 +00:00
nathanw
0eaa8971b7 Use CPP macros to cause many libpthread functions used by applications
to be transformed into the do-nothing-when-libpthread-isn't-linked libc
stub names. This will permit library code that uses <pthread.h> and pthread
functions "defensively" to not need to link against libpthread and not need
to be patched to the threadlib.h API.
2004-12-10 16:40:40 +00:00
skrll
32069ca6a3 pt_sleepuc was removed a long time ago. 2004-12-01 14:27:01 +00:00
nathanw
45204d9ceb Punt to setcontext() system call if the PSL_T bit (single-step trap)
is set, so that the single-step trap happens in the thread's context
and not in the middle of _setcontext_u.

XXX might be able to do something here with iret, too, but it needs
more testing.
2004-11-30 21:05:01 +00:00
kent
63a8cde231 save&restore %fs and %gs registers for USER_LDT applications.
PR#26900
2004-11-10 01:12:57 +00:00
fvdl
5febc5eef5 Fix thread context switching to take the stack ABI into account.
From Wolfgang Solfrank.
2004-10-21 16:49:47 +00:00
mycroft
2b4ccae3e9 Remove pt_blockuc. If the debugger attempts to muck with the state of a
blocked thread, return an error; this should be done through ptrace(2).
2004-10-12 22:17:56 +00:00
nathanw
7c7a36f21d In nanosleep(), loop until the timer fires or a signal is taken; other
spurious wakeups (such as those caused by gdb) should not cause
nanosleep to return prematurely.
2004-08-24 02:08:08 +00:00
nathanw
f83d3766b4 Mark when a thread has taken a signal. 2004-08-24 01:46:30 +00:00
nathanw
3f53b40ca7 Local whitespace police. 2004-08-24 01:45:54 +00:00
nathanw
15c2d9148c Add a flag that indicates that a thread took a signal. 2004-08-24 01:44:08 +00:00
rearnsha
cd8021f51e Use RET macro for returning. 2004-08-21 11:31:44 +00:00
chs
c6736a59b3 redo the fix for PR 26392 differently: instead of changing the stack bounds
for the initial stack, just change the initial thread's pt_uc to point to
the opposite end of the stack (away from the argv, environment, etc).
2004-08-17 14:16:00 +00:00
yamt
6b2b9c625f - fix pthread_detach with an already exit'ed thread.
namely, put the thread to deadqueue rather than just leaking it.
- fix a race between pthread_detach/join and pthread_exit,
  which also causes dead thread leaks.
2004-08-12 10:54:13 +00:00
yamt
129567b88f pthread_rwlock_timedrdlock/pthread_rwlock_timedwrlock:
fix lock/unlock inversions in ERRORCHECK.
2004-08-03 11:50:45 +00:00
yamt
5fc4e57d71 pthread_rwlock_timedwrlock: return ETIMEDOUT appropriately. 2004-08-03 11:40:24 +00:00
nathanw
8bf7374bcf In cond_wait() and cond_timedwait(), do the ERRORCHECK testing of the
waiters list in all cases, not just on cancellation; there are other
sources of spurious wakeups, such as single-stepping in the debugger.

regress/lib/libpthread/conddestroy1 now passes.
2004-07-27 21:44:48 +00:00
chs
503ca60040 in pthread__initmain(), don't reuse the part of the initial stack that
is occupied by the argv and environment (and MD stuff like the page-table
mapping on x86).  fixes PR 26392.
2004-07-25 23:22:43 +00:00
he
b17ac49bb1 Cast result of pthread__uc_pc() via intptr_t before using as a pointer.
Fixes compile problem for evbsh5.
2004-07-20 12:40:53 +00:00
chs
6c4049f2ff fix some stack-pointer math in the previous revision. 2004-07-20 01:51:49 +00:00
chs
e348d7e175 add hppa MD libpthread bits. translated from MIPS. 2004-07-19 03:39:02 +00:00
chs
94a458cedd enhance MI pthreads code to support hppa:
- statically initialize all global spin locks.  on hppa, 0 means
   the lock is held, so leaving them with the default value doesn't work.
 - compare functions pointers using a function-pointer type rather than
   an integral type.  on hppa, function pointers may be indirect,
   so we need to trigger gcc to emit calls to the function-pointer
   canonicalization routines in the millicode.
 - on hppa the stack grows up, so handle that using the STACK_* macros.
2004-07-18 21:24:52 +00:00
nathanw
cb111b5e34 When _SOFT_FLOAT is defined, don't save or restore user FP context.
(note: still needs some mk rules tweaking for MKSOFTFLOAT=yes to pass
-msoft-float to asm builds).
2004-07-10 20:57:00 +00:00
nathanw
821dde500e Fix a comment to say "Edit" instead of "Exit". 2004-07-07 18:21:33 +00:00
simonb
b4f0be566a Catch up with changes to __fpregset_t.
In __longjmp14(), copy the FP CSR from the correct array and array slot.

Completes fix for PR port-mips/25942.
2004-07-03 05:10:06 +00:00
drochner
0e6c93b9fa const'ify the arguments to pthread__assertfunc and _errorfunc;
needed because the __func__ pseudo-var is strictly "const*" in gcc-3.4
2004-06-25 16:33:32 +00:00
nathanw
47513cedb9 If the sleep sleeps for its full time and rmtp is non-NULL, clear it;
sleep(3) expects this, even though it's not a documented property of
nanosleep().

Fixes a problem where sleep() in a threaded program would return
nonzero even on success.
2004-06-24 22:18:11 +00:00
christos
93b9ee2332 simplify and make more efficient (YAMAMOTO Takashi) 2004-06-03 19:32:27 +00:00
nathanw
44a1e00a08 Remove a comment made obsolete by the previous commit. 2004-06-02 22:39:52 +00:00
pooka
aff31bed2f pthread_spin_lock.3 also describes pthread_spin_trylock(),
so link them together
2004-06-02 14:07:07 +00:00
uwe
521748fbfa Fix typo in comment. 2004-05-28 22:58:25 +00:00
christos
556949a68e Oops, forgot to commit this. 2004-05-24 01:20:17 +00:00
christos
7168861fac Provide access to _res in the non-threaded case, and abort in the threaded
case.
2004-05-22 15:44:26 +00:00
kleink
6b3fbf5d75 IEEE Std 1003.1-2001/Cor 2-2004, item XSH/TC2/D6/5: fdatasync() shall
have cancellation points.

Note: we ride today's resolver-related version bumps.
2004-05-21 17:15:42 +00:00
christos
627129c2d3 bump the version of this too. 2004-05-21 04:09:13 +00:00
christos
9b99e159b4 add pool code for res state.
XXX: could be more efficient.
2004-05-21 03:40:51 +00:00
kleink
5a6f0c93e7 In the nothread version, don't return EINTR if select() was interrupted
since this value is explicitly ruled out by POSIX.  Instead, return 0,
like a spurious wakeup.  From YAMAMOTO Takashi in PR standards/24240.
2004-05-03 09:13:34 +00:00
simonb
9bc855a931 s/the the/the/ (only in sources that aren't regularly imported from
elsewhere).
2004-04-23 02:58:27 +00:00
lha
8b387b156a Fix a problem where pthread_kill can set a signal while the process
have the signal blocked, this ends up making target thread getting
later stuck in a loop if it uses pthread_sigmask.

ok, cl and christos
2004-03-24 20:01:37 +00:00
he
99f69b6c5f It appears that <sys/lock.h> requires <sys/types.h>, so include that as well. 2004-03-14 12:49:31 +00:00
cl
f3f745b9af fix comment for recent pthread_stack* var rename 2004-03-14 01:20:01 +00:00
cl
f2f106648c add libpthread part of concurrency support for SA on MP systems
- enable concurrency according to environment variable PTHREAD_CONCURRENCY
- add idle VP wakeup if there are additional jobs and idle VPs
- make reidlequeue per VP
- enable spinning for locks
- fix race condition in alarm processing
- fix race condition in mutex locking
- make debugging output line buffered and add VP prefix to debug lines
2004-03-14 01:19:41 +00:00
thorpej
1cda93b426 Use the new RAS_*() macros. 2004-03-03 21:06:07 +00:00
wiz
85746c6759 Spell interrupt with two rs. From Peter Postma. 2004-02-24 15:16:04 +00:00
wiz
f05e6f1a3a occured -> occurred. From Peter Postma. 2004-02-24 15:12:51 +00:00
wiz
d20841bb64 Uppercase CPU, plural is CPUs. 2004-02-13 11:36:08 +00:00
nathanw
94fc83a6be Add ucontext conversion macros for an "extra" register set. 2004-02-11 21:04:10 +00:00
nathanw
0a6afcc70d Rename pt_stacksize, pt_stacksize_lg, and pt_stackmask to pthread_*. External
symbols can't start with pt_, as that is in the application namespace.
2004-02-02 20:36:18 +00:00
kleink
9f0429b6cc ; may be a comment character in assembly, use \n as a separator instead.
This instance spotted by Martin Husemann.
2004-01-19 16:18:33 +00:00
cl
359b937c80 - delay making a thread unblocked until it's put on the runqueue.
- simplify handling of blocked idle threads.

This should fix the ``assertion "target->pt_state != PT_STATE_RUNNING
|| target->pt_blockgen != target->pt_unblockgen" failed'' problem
reported by Marc Recht and Steve Bellovin on current-users.

Also g/c unused pthread__sched_bulk call left over from pthread_sa.c
rev. 1.22 change.
2004-01-16 15:23:31 +00:00
cl
c8017c0dc6 - add deadlock check to pthread_rwlock_wrlock and pthread_rwlock_timedwrlock
- return EPERM when unlocking a lock which isn't held
=> prevent the failure in PR 24023, where the citrus code had a deadlocking
   code path

- remove deadlock check in pthread_rwlock_tryrdlock, return EBUSY instead
=> makes pthread_rwlock_tryrdlock standards compliant
2004-01-09 18:08:28 +00:00
cl
f35871411a make siglongjmp out of a signal handler work:
- strong alias __sigprocmask14 to pthread_sigmask
- call _sys___sigprocmask14 where appropriate
- make pthread_sigmask not set the signal mask lazily when pthreads
  aren't started yet
2004-01-02 19:24:44 +00:00
cl
33622a5943 userland part of no-syscall upcall stack return
- add pt_stackinfo to struct __pthread_st
- add pthread__stackinfo_offset returning the offset from ss_sp to
  pt_stackinfo
- pass stackinfo_offset to sa_register and set SA_FLAG_STACKINFO to
  make the kernel use it
- call pthread__sa_recycle in pthread__resolve_locks; g/c recycleq and
  pthread__recycle_bulk
- return stack in pthread__sa_recycle by incrementing sasi_stackgen
- make pthread__sa_recycle debugging output formatting conditional on
  pthread__debug_newline
2004-01-02 19:14:00 +00:00
cl
90e89977d4 - libc.so.12.109 and libpthread.so.0.4
- add ssize_t stackinfo_offset argument to sa_register syscall
- remove sa_unblockyield syscall
- make __sigprocmask14 syscall weak
- in pthread__sa_start: catch up with 4-argument sa_register syscall
2004-01-02 18:56:39 +00:00
cl
91d9c8c22f pthread__upcall: output LWPid in SA_UPCALL_BLOCKED case 2004-01-02 14:29:22 +00:00
cl
677748c645 logging/debugging changes:
- add PTHREAD_PID_DEBUG which prints the pid before each debuglog line
- output thread returned in pthread__next
- add asserts in pthread__sched akin to asserts in pthread__sched_bulk:
  check if scheduled thread is at front/end of queue
- pthread__upcall: output event/interrupted LWP count instead of LWPid
  of the first event/interrupted LWP (since unblock upcalls can have
  multiple event LWPs).
- pthread__find_interrupted: output LWPid here
2004-01-02 14:13:16 +00:00
lukem
d597f546a1 Add dependencies to assym.h on:
pthread.h pthread_int.h pthread_md.h
Should help prevent the problem I raised in [kern/23946], based on
a hint from Christian Limpach.

Add MAKEVERBOSE support.
2004-01-02 01:37:53 +00:00
cl
82b6b2dbda Handle block/unblock for threads in critical section without
sa_unblockyield.

XXX g/c sa_unblockyield in kernel later
2003-12-31 16:45:48 +00:00
christos
b7559f8576 PR/23791: Patrick Latify: Fix memory leak on thread creation failure. 2003-12-18 15:39:56 +00:00
jmc
d9948df6dd Clean up tmp files on exit. Fixes PR#23723 2003-12-15 20:07:39 +00:00
christos
1edf98ec41 Add pthread_{g,s}etschedparam, that do nothing. 2003-12-07 20:29:07 +00:00
cl
2c9b7b1eb7 Set default stack size to the current limit on the stack size as set
with the shell's command to change limits.  Make the PTHREAD_STACKSIZE
environment variable override the default stack size.  The old fixed
stack size behaviour can be enable with PT_FIXEDSTACKSIZE_LG when building
libpthread.
2003-11-27 16:30:54 +00:00
he
ea56bcee84 Hide the register number constants behind an _R_ prefix, and also
rename FPBASE to _FPBASE, so that we avoid polluting the user's
name space when e.g. <sys/ptrace.h> is included.  Previously, the
PC symbol in mips/regnum.h would conflict with the declaration of
the external variable by the same name in termcap.h, as discovered
by the ``okheaders'' regression test.
2003-11-26 08:36:49 +00:00
cl
11127744bf Save the old mask in the old context, not in the new one. 2003-11-25 23:55:27 +00:00
cl
d109665f1d Honor SA_NODEFER in pthread__deliver_signal(). This should help code which
makes a longjmp out of a signal handler.

Also add missing si_code argument to debugging printf in pthread__kill().
2003-11-25 22:45:33 +00:00
christos
0446e60323 Update list of items. 2003-11-25 22:44:16 +00:00
christos
adfca9e3e4 This is not needed anymore. 2003-11-25 22:41:12 +00:00
christos
5077d05f7b GC sigcontext<->mcontext code and __HAVE_SIGINFO. All supported archs have
siginfo implemented.
2003-11-25 22:36:32 +00:00
christos
69658517e0 - don't store sigmask on the stack, we could store it in the right place
[in the context]
- this has the side effect of fixing the problem of the signal mask not
  being preserved properly upon signal return, found and fixed by cl.
- add si_code to the tramp debugging output (requested by cl).
2003-11-25 22:26:44 +00:00
christos
6477735848 m68k does not sigcontext<->mcontext anymore. 2003-11-25 21:27:30 +00:00
cl
774b4b225b Update mutex/rwlock/sem code to match recent change in cond code. 2003-11-24 23:54:13 +00:00
cl
4f8ea51319 add CONSTCOND in constant condition. 2003-11-24 23:23:17 +00:00
nathanw
250e7bbf8e Fix a race between timed wait callbacks and manual signal/broadcasting
accidentally introduced in rev. 1.5.

Noted by Christian Limpach.
2003-11-24 22:54:31 +00:00
nathanw
cdf7f99ee6 Manually inline pthread__testcancel in these routines; two function
calls' worth of overhead per cancellable syscall is overkill.
2003-11-21 23:03:13 +00:00
nathanw
4e755ddba8 Prevent ptc_mutex from remaining set if a CV sleep is woken by
cancellation:

 * Arrange to not set ptc_mutex until after the pre-sleep cancellation
   test.

 * In the post-sleep cancellation test, check if there are no more
   sleepers and clear ptc_mutex if so.

While here, sprinkle some __predict_false() around the cancellation
tests.
2003-11-21 22:08:00 +00:00
uwe
6d08061385 Do not move incoming paramters to callee-save registers when not
necessary.  Saves about a dozen of instructions.
2003-11-20 17:55:11 +00:00
uwe
4b13bb93a0 Follow-up to previous. In pthread__signal_tramp() maskp is below
siginfo on the stack, so get it from there.  ss_sp no longer points to
the the mask.  Pointed out by cl@.
2003-11-20 17:45:00 +00:00
uwe
b3c165e505 Add _INITCONTEXT_U_MD, we need to clean _REG_SR. 2003-11-20 17:38:08 +00:00
uwe
f5cd7f26ed Undo previous. In pthread__deliver_signal set uc->uc_stack.ss_sp = uc;
(as it used to be before 1.1.2.12) so that makecontext doesn't stomp
on the data we allocated on the stack.  Correct the debugging printf
to print olduc instead of target->pt_uc (we have pt_trapuc now, and
olduc can be pt_trapuc).
2003-11-20 17:16:41 +00:00
yamt
d7b65981fb pthread__deliver_signal: swap oldmask and siginfo so that signal
handler's stack doesn't stomp siginfo.
this also fixes !__HAVE_SIGINFO, in that case
pthread__signal_tramp assumes uc->uc_stack.ss_sp points the old
signal mask.

pointed by uwe@.
2003-11-20 15:46:42 +00:00
uwe
1e78682585 In pthread__locked_switch set self->pt_uc only when the context is inited.
In STACK_SWITCH subtract STACKSPACE, not add it (it's zero for now anyway).
2003-11-20 03:31:02 +00:00
uwe
024d461f8f First cut at pthreads MD code for sh3. Based on m68k version.
Regression tests still failing: sem, sigalarm.
2003-11-18 03:11:41 +00:00
uwe
f9cb911365 Add necessary symbols. 2003-11-18 03:07:29 +00:00
thorpej
88ed237274 Bump libc to 12.107 and libpthread to 0.3 for fsync_range(2). 2003-11-18 01:00:19 +00:00
thorpej
137c808bb8 Userland portion of fsync_range(2), written by Bill Studenmund, and
contributed by Wasabi Systems, Inc.
2003-11-18 00:56:56 +00:00
cl
196dbdcd2b - delay processing unblocked threads until after locks are resolved:
without the blocked/unblocked upcall ordering, an interrupted blocked
  upcall might put the blocked thread on the intqueue because it needs
  to be continued.  With the delayed processing, we avoid putting such a
  thread twice on the runqueue.
- fix putting a thread on the intqueue when it needs to be continued
  after it blocked.

Also check return value when returning a single stack.
2003-11-17 22:59:00 +00:00
uwe
764c596c3f Cause SIGTRAP if NOTREACHED code is reached. 2003-11-17 22:38:11 +00:00
cl
803f13c062 check deferred signals for all unblocked threads 2003-11-12 22:21:21 +00:00
wiz
c3c78af0ec Various fixes. 2003-11-12 11:58:34 +00:00
christos
c8608b903b Document pthread_attr_setcreatesuspend_np, pthread_suspend_np, pthread_resume_np 2003-11-12 02:44:22 +00:00
martin
3e8ef3d56a Fix ucontext conversion macros. From Christian Limpach. 2003-11-11 16:21:05 +00:00
martin
d708163f7f All the ucontext <-> {fp}reg macros were slightly simplistic and untested
before (old gdb support on sparc did not use this).
Pointed out by Christian Limpach.
2003-11-10 07:52:52 +00:00
christos
38b1c6f405 Add:
int    pthread_attr_setcreatesuspend_np(pthread_attr_t *);
int    pthread_suspend_np(pthread_t);
int    pthread_resume_np(pthread_t);

needed for java. Approved and fixed by cl.
2003-11-09 18:56:48 +00:00
fvdl
c4e432f3bd Make register usage more consistent, also in comparison with the i386
version, for easier maintenance.
2003-11-08 21:46:42 +00:00
fvdl
127827f46e Restore %rax correctly during a full context restore (oops). 2003-11-08 21:45:59 +00:00
wiz
85cc64da0f Typo; from Jared Yanovich via jmc@openbsd. 2003-11-02 11:18:10 +00:00
yamt
71b290e975 use explicit "l" suffixes. (eg. lea -> leal) 2003-10-30 13:56:37 +00:00
wiz
bc81ecac30 sigwait(2), not (3). 2003-10-30 12:57:11 +00:00
jdolecek
e2e1314ccd bump date too 2003-10-30 11:53:33 +00:00
jdolecek
f65cf67b62 xref sigwait(3) 2003-10-30 11:51:42 +00:00
cl
812a254c5d remove incorrect assert:
regular threads can block in the kernel while holding (libpthread) locks
and have to be continued

XXX if the blocked upcall is preempted, the blocked threads syscall
XXX return value can get lost
2003-10-29 18:53:34 +00:00
lukem
f85d2d1c14 Use ${HOST_SH} instead of `sh'.
If necessary, pull in <bsd.sys.mk> to get the definition of HOST_SH;
Makefiles that pull in one of (most of) <bsd.*.mk> will get this anyway.
2003-10-26 07:25:33 +00:00
yamt
2016949b00 update a comment. 2003-10-24 17:35:22 +00:00
fvdl
c2405107f1 Correct and simplify computing the return point; just use PC-relative
addressing.
2003-10-20 14:50:18 +00:00
fvdl
b30e737545 Make sure the stack stays aligned. 2003-10-19 21:45:03 +00:00
yamt
5cd18e71cc in pthread__deliver_signal(),
copy siginfo_t into the stack of the target thread
rather than relying on the luck that on-stack siginfo_t stay valid.
2003-10-16 13:38:28 +00:00
chs
f58c80fc8f fix typo in previous. 2003-10-12 00:25:25 +00:00
wiz
37ac1db454 available, not avaliable. From miod@openbsd. 2003-09-29 09:50:21 +00:00
nathanw
9839173881 Don't include <machine/lock.h> anymore; instead, we now get
__cpu_simple_lock_t and __SIMPLELOCK_{UN,}LOCKED from <sys/types.h>.
Should prevent the massive namespace pollution by way of dragging in
many MD headers that has been observed to break stuff.
2003-09-26 22:48:23 +00:00
cl
bfa716044e SA_SIGINFO support for m68k (libpthread) 2003-09-22 14:45:48 +00:00
cl
c6de69ee49 fix pt_trapuc handling errors:
- movl to address register doesn't set flags (add explicit test)
- clr only clears a word (use clrl)
2003-09-17 20:08:07 +00:00
cl
5c40d56471 fix SA/pthread pagefault failure:
- prevent BLOCKED upcalls on double page faults and during upcalls
- make libpthread handle blocked threads which hold locks
- prevent UNBLOCKED upcalls from overtaking their BLOCKED upcall
this adds a new syscall sa_unblockyield
see also http://mail-index.netbsd.org/tech-kern/2003/09/15/0020.html
2003-09-16 13:51:31 +00:00
christos
86d645082f fix syntax; thanks aymeric 2003-09-13 17:19:55 +00:00
christos
d1bb4290e8 explicitly use a sigset_t * variable to recover the signal mask pointer. 2003-09-13 15:26:38 +00:00
drochner
45a9abb6af make it compile with PTHREAD_SIG_DEBUG again 2003-09-12 15:31:00 +00:00
kleink
8742dcef75 Fix pasto in previous. 2003-09-12 10:10:39 +00:00
christos
138df80b74 convert to use siginfo/ucontext style of signal delivery instead of
sigcontext. Approved by nathanw.
2003-09-12 00:37:17 +00:00
christos
338cc5f663 sprinkle ARGSUSED for good cheer. 2003-09-11 21:51:57 +00:00
cl
89d0cfd21f Remove possible race condition in upcall recycling. 2003-09-07 14:47:44 +00:00
uwe
b5623b232f Use delay slot in STACK_SWITCH (catching up with sparc64 changes). 2003-09-07 02:08:31 +00:00
uwe
7d522ba08b Use correct context to switch to.
From sparc64 fix by Andrey Petrov <petrov@netbsd>.
2003-09-07 01:54:47 +00:00
petrov
0d472e116b typo in previous commit, annul isn't good there,
noticed by Eduardo Horvath.
2003-08-26 17:50:06 +00:00
petrov
2cae323122 Use branch-slot in STACK_SWITCH, suggested by Martin Husemann. 2003-08-25 23:00:23 +00:00
petrov
c139cd4893 Use correct context to switch to. 2003-08-25 22:48:24 +00:00
ragge
644236bf71 Add PT_TRAPUC and pthread__switch_return_point.
Not tested (as most of the pthread stuff on vax) but at least
allow the system to compile.
2003-08-25 20:32:13 +00:00
nathanw
e1fb9dd8e8 In pthread__deliver_signal(), correctly use pt_trapuc or pt_uc as the
context-to-restore instead of always using pt_uc.

Fixes a problem with signal handlers for synchronous signals noted by
Matthias Drochner on current-users.
2003-08-22 17:35:52 +00:00
martin
88055fbde5 Include <stdlib.h> for exit() prototype. 2003-08-20 09:50:16 +00:00
nathanw
bd9a18b79f Split out pthread_{set,get}specific() into a separate file and arrange
for that file to not be built with profiling. This makes it reasonable to
use pthread_{set,get}specific() to implement thread-safe profiline call counts.
2003-08-13 18:52:01 +00:00
scw
46fc66f7d8 Adapt to Nathan's recent pt_trapuc/pt_sleepuc change. 2003-08-12 14:01:08 +00:00
agc
eb7c1594f1 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22280, verified by myself.
2003-08-07 16:42:00 +00:00
lukem
a93ea220fc Rework how dependency generation is performed:
* DPSRCS contains extra dependencies, but is _NOT_ added to CLEANFILES.
  This is a change of behaviour.  If a Makefile wants the clean semantics
  it must specifically append to CLEANFILES.
  Resolves PR toolchain/5204.

* To recap: .d (depend) files are generated for all files in SRCS and DPSRCS
  that have a suffix of: .c .m .s .S .C .cc .cpp .cxx

* If YHEADER is set, automatically add the .y->.h to DPSRCS & CLEANFILES

* Ensure that ${OBJS} ${POBJS} ${LOBJS} ${SOBJS} *.d  depend upon ${DPSRCS}

* Deprecate the (short lived) DEPENDSRCS


Update the various Makefiles to these new semantics; generally either
adding to CLEANFILES (because DPSRCS doesn't do that anymore), or replacing
specific .o dependencies with DPSRCS entries.

Tested with "make -j 8 distribution" and "make distribution".
2003-08-01 17:03:41 +00:00
kleink
7d3a44f705 Remove PT_SLEEPUC, which somehow wasn't. 2003-07-29 15:18:49 +00:00
salo
99410184e7 netbsd.org->NetBSD.org 2003-07-26 19:24:24 +00:00
mrg
9759912dd6 need <string.h> 2003-07-26 18:33:06 +00:00
skrll
795970599f Typo in comment. 2003-07-24 08:03:44 +00:00
wiz
576530e520 Add pthread(3), based on one by Hubert Feyrer, improved by yours truly,
reviewed by Nathan J. Williams.
2003-07-24 07:50:24 +00:00
nathanw
0878df5d25 Lock accesses to pt_flags and pt_cancel.
When disabling cancellation, clear the pt_cancel flag if it was set
and note the cancellation request with PT_FLAG_CS_PENDING. This avoids
a problem where a cancellation request entered but not acted upon before
pthread_setcanclstate(PTHREAD_CANCEL_DISABLE) is called would still be
aceted upon before cancellation was re-enabled.
2003-07-21 22:24:09 +00:00
nathanw
329747fb90 Add a lock on the pt_flags field. 2003-07-21 22:21:07 +00:00
nathanw
0c96790183 Use _sys_write() instead of write() in the assertion and error
functions, to avoid invoking the cancellation machinery in the middle
of trying to print an assertion or error message.
2003-07-21 22:17:14 +00:00
nathanw
68a63a4079 Move initialization of variable 'nthreads' so that pthread_exit() from
the main thread, with no other threads created, exits cleanly instead
of triggering an assertion in pthread_next().
2003-07-21 22:14:57 +00:00
nathanw
ec2c169839 pthread.c was getting a bit unwieldly. Move pthread_attr stuff out
into a new file, and put the shared private structure definition in
pthread_int.h.
2003-07-18 22:33:45 +00:00
nathanw
0172694e7d Implement a bunch of pthread_attr_() functions, which genuinely set and examine
pthread_attr_t objects, although most of the properties being set don't really
affect threads yet:

pthread_attr_{get,set}guardsize()
pthread_attr_{get,set}inheritsched()
pthread_attr_{get,set}scope()
pthread_attr_{get,set}stack()
pthread_attr_setstack{size,addr}()

Remove some useless assertions and error checks in the existing pthread_attr()
routines.

Implement pthread_attr_get_np(), to examine the attributes of an existing
thread. Idea and interface from FreeBSD.

Change PTHREAD_ERRORMODE environment variable to PTHREAD_DIAGASSERT, and
make it behave like libc's LIBC_DIAGASSERT. The way to disable error-checking
and aborting is now "PTHREAD_DIAGASSERT=AEL", rather than
"PTHREAD_ERRORMODE=ignore".
2003-07-18 22:12:30 +00:00
nathanw
067fa34e42 Add prototypes and necessary symbols for a bunch of pthread_attr_*() functions,
including (interface borrowed from FreeBSD) pthread_attr_get_np().

Remove a few limit-indicating symbols that don't actually need to be defined
(and if they did need to be defined, it would be in limits.h, not here).
2003-07-18 22:01:47 +00:00
nathanw
9e5c87057d Add strong alias for setcancelstate. 2003-07-18 21:57:26 +00:00
lukem
98e8a6d142 #include <pthread_types.h> instead of "pthread_types.h" 2003-07-18 15:58:43 +00:00
nathanw
1a9edd35f7 Simplify pthread__stackalloc() by using the newish aligned-mmap()
feature.
2003-07-17 21:07:39 +00:00
nathanw
d686fc0deb Define PTHREAD_* structure initializers from _PTHREAD_* macros from
pthread_types.h.
2003-07-17 20:59:35 +00:00
nathanw
d37a996a49 Adapt to structure name changes. 2003-07-17 20:55:25 +00:00
nathanw
deb18e9d04 Adapt to internal structure name changes.
Add a couple of useful flags and symbols.
2003-07-17 20:52:38 +00:00