Commit Graph

445 Commits

Author SHA1 Message Date
davidxu
eed69ab82a Save and restore timeout field for signal frame just like what we did
for interrupted field.
Also in _thr_sig_handler, retrieve current signal mask from kernel not
from ucp, the later is pre-unioned mask, not current signal mask.
2003-09-22 14:40:36 +00:00
davidxu
b429e20750 Fix FPU state restoring bug by jumping to right position. 2003-09-22 14:34:02 +00:00
davidxu
96155432c1 Print waitset correctly. 2003-09-22 00:40:23 +00:00
marcel
265b2be119 Make KSE_STACKSIZE machine dependent by moving it from thr_kern.c to
pthread_md.h. This commit only moves the definition; it does not
change it for any of the platforms. This more easily allows 64-bit
architectures (in particular) to pick a slightly larger stack size.
2003-09-19 23:28:13 +00:00
marcel
5888af272d _ia64_break_setcontext() now takes a mcontext_t. While here, define
THR_SETCONTEXT as PANIC(). The THR_SETCONTEXT macro is currently not
used, which means that the definition we had could be wrong, overly
pessimistic or unknowingly right. I don't like the odds...

The new _ia64_break_setcontext() and corresponding kernel fixes make
KSE mostly usable. There's still a case where we don't properly
restore a context and end up with a NaT consumption fault (typically
an indication for not handling NaT collection points correctly),
but at least now mutex_d works...
2003-09-19 23:00:28 +00:00
marcel
ef50cc82f8 Stop using the setcontext() syscall to restore an async context.
Instead use the break instruction with an immediate specially
created for us.
2003-09-19 22:54:05 +00:00
davidxu
85f4a8612b pthread api should return error code in return value, not in errno. 2003-09-18 12:19:28 +00:00
davidxu
e7f6efc66e Fix a typo. Also turn on PTHREAD_SCOPE_SYSTEM after fork(). 2003-09-16 02:03:39 +00:00
deischen
7332e364d0 Remove a comment that questioned why the size of the FPU
state for amd64 was twice as large as necessary.  Peter
recently fixed this, so the comment no longer applies.

Also, since the size of struct mcontext changed, adjust
the threads library version of get&set context to match.

FYI, any change layout/size change to any arch's struct
mcontext will likely need some minor changes in libpthread.
2003-09-16 00:00:53 +00:00
davidxu
1d188498a3 Fix bogus comment and assign sigmask in critical region, use
SIG_CANTMASK to remove unmaskable signal masks.
2003-09-15 00:08:48 +00:00
davidxu
8d7f2fb390 Fix a bogus comment, sigmask must be maintained correctly,
it will be inherited in pthread_create.
2003-09-15 00:06:46 +00:00
davidxu
42c958f29f 1. Allocating and freeing lock related resource in _thr_alloc and _thr_free
to avoid potential memory leak, also fix a bug in pthread_create, contention
   scope should be inherited when PTHREAD_INHERIT_SCHED is set, and also check
   right field for PTHREAD_INHERIT_SCHED, scheduling inherit flag is in sched_inherit.
2. Execute hooks registered by atexit() on thread stack but not on scheduler
   stack.
3. Simplify some code in _kse_single_thread by calling xxx_destroy functions.

Reviewed by: deischen
2003-09-14 22:52:16 +00:00
davidxu
40d912b465 When invoking an old style signal handler, use true traditional BSD style to
invoke signal handler.

Reviewed by: deischen
2003-09-14 22:42:39 +00:00
davidxu
b622332e18 Respect POSIX specification, a value return from pthread_attr_getguardsize
should be a value past to pthread_attr_setguardsize, not a rounded up value.
Also fix a stack size matching bug in thr_stack.c, now stack matching code
uses number of pages but not bytes length to match stack size, so for example,
size 512 bytes and size 513 bytes should both match 1 page stack size.

Reviewed by: deischen
2003-09-14 22:39:44 +00:00
davidxu
d08173b50b Avoid garbage bits in c_flags by direct assigning value.
Reviewed by: deischen
2003-09-14 22:33:32 +00:00
davidxu
b117b7ad58 If user is seting scope process flag, clear PTHREAD_SCOPE_SYSTEM bit
accordingly.

Reviewed by: deischen
2003-09-14 22:32:28 +00:00
davidxu
be9fb27b11 Check invalid parameter and return EINVAL.
Reviewed by: deischen
2003-09-14 22:28:13 +00:00
davidxu
707186a985 Original pthread_once code has memory leak if pthread_once_t is used in
a shared library or any other dyanmic allocated data block, once
pthread_once_t is initialized, a mutex is allocated, if we unload the
shared library or free those data block, then there is no way to deallocate
the mutex, result is memory leak.
To fix this problem, we don't use mutex field in pthread_once_t, instead,
we use its state field and an internal mutex and conditional variable in
libkse to do any synchronization, we introduce a third state IN_PROGRESS to
wait if another thread is already in invoking init_routine().
Also while I am here, make pthread_once() conformed to pthread cancellation
point specification.

Reviewed by: deischen
2003-09-09 22:38:12 +00:00
davidxu
f2dd9e6365 Add code to support pthread spin lock.
Reviewed by: deischen
2003-09-09 06:57:51 +00:00
davidxu
521fd6195a Add small piece of code to support pthread_rwlock_timedrdlock and
pthread_rwlock_timedrwlock.
2003-09-06 00:07:52 +00:00
kan
3cec797a7b The caller is expected to set up PIC register corectly before
jumping to .cerror. This means .cerror has to be present in the
same module with its consumers, or bad things will happen.
2003-09-05 18:08:19 +00:00
davidxu
82aeb9fc85 Add code to support barrier synchronous object and implement
pthread_mutex_timedlock().

Reviewed by: deischen
2003-09-04 14:06:43 +00:00
davidxu
480778ce65 Remove repeated macro THR_IN_CONDQ. 2003-09-04 07:46:26 +00:00
davidxu
962cbaebac Allow hooks registered by atexit() to run with current thread pointer set,
without this change, my atexit test dumps core.
2003-09-04 05:24:53 +00:00
deischen
919bc52171 Don't assume sizeof(long) = sizeof(int) on x86; use int
instead of long types for low-level locks.

Add prototypes for some internal libc functions that are
wrapped by the library as cancellation points.

Add memory barriers to alpha atomic swap functions (submitted
by davidxu).

Requested by:	bde
2003-09-03 17:56:26 +00:00
davidxu
f61d4432c4 Move kse_wakeup_multi call to just before KSE_SCHED_UNLOCK.
Tested on: SMP
2003-09-03 00:21:10 +00:00
kan
6d12300f90 Rethink the way thr_libc.So is generated. Relying on GCC to extract
only needed symbols from libc_pic is not working on sparc64.

Requested by: jake
2003-09-02 19:37:11 +00:00
deischen
e8c434f7c5 Allow the concurrency level to be reduced.
Reviewed by:	davidxu
2003-08-30 12:09:16 +00:00
davidxu
6c1cd2954d Repost masked signal to kernel for scope system thread, it hardly happens
in real world.

Reviewed by: deischen
2003-08-21 22:02:18 +00:00
davidxu
5546ba5027 _thr_sig_check_pending is also called by scope system thread when it leaves
critical region, we wrap some syscalls for thread cancellation point, and
when syscalls returns, we call _thr_leave_cancellation_point, at the time
if a signal comes in, it would be buffered, and when the thread leaves
_thr_leave_cancellation_point, buffered signals will be processed, to avoid
messing up normal syscall errno, we should save and restore errno around
signal handling code.
2003-08-20 13:43:35 +00:00
deischen
9371b61282 Add back a loop for up to PTHREAD_DESTRUCTOR_ITERATIONS to
destroy thread-specific data.  Display a warning when thread
specific data remains after PTHREAD_DESTRUCTOR_ITERATIONS.

Reviewed by:	davidxu
2003-08-20 02:34:14 +00:00
davidxu
00e9963efb Support printing 64 bits pointer and long integer.
Reviewed by: deischen
2003-08-19 08:29:33 +00:00
davidxu
0e9eb96aee Save and restore errno around sigprocmask. 2003-08-19 03:33:51 +00:00
davidxu
49037ec1b2 Direct call exit if thread was never created. This makes it safe to call
pthread_exit in main() without creating any thread.

Tessted by: deischen
2003-08-18 04:03:08 +00:00
davidxu
3203dde90e Treat initial thread as scope system thread when KSE mode is not activated
yet, so we can protect some locking code from being interrupted by signal
handling. When KSE mode is turned on, reset the thread flag to scope process
except we are running in 1:1 mode which we needn't turn it off.
Also remove some unused member variables in structure kse.

Tested by: deischen
2003-08-18 03:58:29 +00:00
davidxu
76d162d172 If threaded mode is not turned on yet, direct call __sys_sched_yield. 2003-08-16 13:02:45 +00:00
davidxu
e695327086 Keep initial kse and kse group just like we keep initial thread,
Don't free them, so some code can still reference them.

Reviewed by: deischen
2003-08-16 05:22:20 +00:00
davidxu
206928815a Access user provided pointer out of lock, and also check the case when
a key is less than 0.
2003-08-16 05:19:00 +00:00
marcel
8e205a2f04 Don't run verify directly as that would require the perl script to
have execute permissions. Run "perl verify" instead. Replace all
occurences of the hardcoding of ./verify with $(VERIFY) to allow
it to be overridden as well.
2003-08-13 03:59:18 +00:00
davidxu
f9f5048801 Always set tcb for bound thread, and switch tcb for M:N thread at correct
time.
2003-08-13 01:49:07 +00:00
davidxu
2bb2e522ee Don't forget to set kcb_self. 2003-08-12 22:13:06 +00:00
davidxu
c5eb02d502 Correctly set current tcb. This fixes some IA64/KSE problems.
Reviewed by: deischen, julian
2003-08-12 08:01:34 +00:00
davidxu
09416455b1 Add some quick pathes to exit process when signal action is default and
signal can causes process to exit.

Reviewed by: deischen
2003-08-10 22:35:46 +00:00
davidxu
4d41804986 Initialize rtld lock just before turning on thread mode and
uninitialize rtld lock after thread mode shutdown.
2003-08-10 22:30:20 +00:00
davidxu
b614f44d78 If thread mode is not activated yet, just call __sys_fork() directly,
otherwise masks all signals until fork() returns, in child process,
we reset library state before restoring signal masks until we reach
a safe to point.

Reviewed by: deischen
2003-08-10 22:20:41 +00:00
davidxu
349a8e7e9b Tweak rtld lock to allow recursive on reader lock and detect recursive
on writer lock. This is first cut at rwlock for rtld.

Submitted by: desichen
2003-08-10 22:15:03 +00:00
davidxu
b213a2432e If thread mode is not activated yet, don't do extra work.
Reviewed by: deischen
2003-08-10 22:07:28 +00:00
davidxu
6245694474 o Add code to GC freed KSEs and KSE groups
o Fix a bug in kse_free_unlocked(), kcb_dtor shouldn't be called because
  the KSE is cached and will be resued in _kse_alloc().

Reviewed by: deischen
2003-08-08 22:20:59 +00:00
kan
0faaaf6049 Allow gcc driver to process -r option iself, do not use -Wl,-r to
bypass it. Doing otherwise did not allow compiler to detect and disable
conflicting options generated from specs.

Reported by:	jake
2003-08-08 03:41:13 +00:00
marcel
0dae148272 Grok async contexts. When a thread is interrupted and an upcall
happens, the context of the interrupted thread is exported to
userland. Unlike most contexts, it will be an async context and
we cannot easily use our existing functions to set such a
context.
To avoid a lot of complexity that may possibly interfere with
the common case, we simply let the kernel deal with it. However,
we don't use the EPC based syscall path to invoke setcontext(2).
No, we use the break-based syscall path. That way the trapframe
will be compatible with the context we're trying to restore and
we save the kernel a lot of trouble. The kind of trouble we did
not want to go though ourselves...

However, we also need to set the threads mailbox and there's no
syscall to help us out. To avoid creating a new syscall, we use
the context itself to pass the information to the kernel so that
the kernel can update the mailbox. This involves setting a flag
(_MC_FLAGS_KSE_SET_MBOX) and setting ifa (the address) and isr
(the value).
2003-08-07 08:03:05 +00:00