Commit Graph

497 Commits

Author SHA1 Message Date
davidxu
dd12e67260 Because sleepqueue may still being used, we should always check wchan with
queue locked.
2011-01-04 05:35:19 +00:00
davidxu
1d89f14a5c Always clear flag PMUTEX_FLAG_DEFERED when unlocking, as it is only
significant for lock owner.
2010-12-24 07:41:39 +00:00
davidxu
72cc2acc23 Add sleep queue code. 2010-12-22 05:03:24 +00:00
davidxu
437ad27f9c MFp4:
- Add flags CVWAIT_ABSTIME and CVWAIT_CLOCKID for umtx kernel based
  condition variable, this should eliminate an extra system call to get
  current time.

- Add sub-function UMTX_OP_NWAKE_PRIVATE to wake up N channels in single
  system call. Create userland sleep queue for condition variable, in most
  cases, thread will wait in the queue, the pthread_cond_signal will defer
  thread wakeup until the mutex is unlocked, it tries to avoid an extra
  system call and a extra context switch in time window of pthread_cond_signal
  and pthread_mutex_unlock.

The changes are part of process-shared mutex project.
2010-12-22 05:01:52 +00:00
davidxu
344bdcae88 Use sysctl kern.sched.cpusetsize to retrieve size of kernel cpuset. 2010-11-02 02:13:13 +00:00
davidxu
f8b62a4759 Return previous sigaction correctly.
Submitted by:	avg
2010-10-29 09:35:36 +00:00
davidxu
fa0e722e16 Remove local variable 'first', instead check signal number in memory,
because the variable can be in register, second checking the variable
may still return true, however this is unexpected.
2010-10-29 07:04:45 +00:00
davidxu
8475a5bf0d Check small set and reject it, this is how kernel did. Always use the
size kernel is using.
2010-10-27 09:59:43 +00:00
davidxu
f8f25f57e2 - Revert r214409.
- Use long word to figure out sizeof kernel cpuset, hope it works.
2010-10-27 09:29:03 +00:00
davidxu
d60836560b Remove locking and unlock in pthread_mutex_destroy, because
it can not fix race condition in application code, as a result,
the problem described in PR threads/151767 is avoided.
2010-10-27 04:19:07 +00:00
davidxu
b4fee3c1ed Fix typo. 2010-10-25 11:16:50 +00:00
davidxu
36f64247c7 Get cpuset in pthread_attr_get_np() and free it in pthread_attr_destroy().
MFC after:	7 days
2010-10-25 09:16:04 +00:00
davidxu
1126acd0dc Revert revision 214007, I realized that MySQL wants to resolve
a silly rwlock deadlock problem, the deadlock is caused by writer
waiters, if a thread has already locked a reader lock, and wants to
acquire another reader lock, it will be blocked by writer waiters,
but we had already fixed it years ago.
2010-10-20 02:34:02 +00:00
davidxu
86b8c070d5 Set default type to PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, this
is the type we are using.
2010-10-18 23:37:56 +00:00
davidxu
92672df66c sort function name. 2010-10-18 05:16:44 +00:00
davidxu
a7a5cfca82 s/||/&& 2010-10-18 05:15:26 +00:00
davidxu
c6d578b870 Add pthread_rwlockattr_setkind_np and pthread_rwlockattr_getkind_np, the
functions set or get pthread_rwlock type, current supported types are:
   PTHREAD_RWLOCK_PREFER_READER_NP,
   PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
   PTHREAD_RWLOCK_PREFER_WRITER_NP,
default is PTHREAD_RWLOCK_PREFER_WRITER_NONCECURSIVE_NP, this maintains
binary compatible with old code.
2010-10-18 05:09:22 +00:00
davidxu
de54e693fd Oops, don't remove -fexceptions flag. 2010-10-08 01:53:33 +00:00
davidxu
3bf7c8781d unwind.h was imported, gcc directory is no longer needed. 2010-10-08 01:47:14 +00:00
davidxu
86d9958ce8 change code to use unwind.h. 2010-09-30 12:59:56 +00:00
davidxu
df6acfd7c4 Check invalid mutex in _mutex_cv_unlock. 2010-09-29 06:06:58 +00:00
davidxu
f329bc965c In current code, statically initialized and destroyed object have
same null value, the code can not distinguish between them, to
fix the problem, now a destroyed object is assigned to a non-null
value, and it will be rejected by some pthread functions.
PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP is changed to number 1, so that
adaptive mutex can be statically initialized correctly.
2010-09-28 04:57:56 +00:00
davidxu
56cf3f4638 Report death event to debugger before moving to gc list, otherwise
debugger may can not find it on thread list.
2010-09-26 06:45:24 +00:00
davidxu
6b8f97b128 Only access unwind_disabled when _PTHREAD_FORCED_UNWIND is defined. 2010-09-25 09:43:24 +00:00
davidxu
6405ab4b6c Add missing field. 2010-09-25 08:36:46 +00:00
davidxu
121f2e2d60 Because old _pthread_cleanup_push/pop do not have frame address,
it is incompatible with stack unwinding code, if they are invoked,
disable stack unwinding for current thread, and when thread is
exiting, print a warning message.
2010-09-25 06:27:09 +00:00
davidxu
2aedc66f12 Simplify code, and in while loop, fix operator to match the unwinding
direction.
2010-09-25 04:21:31 +00:00
davidxu
74604ed9c4 To support stack unwinding for cancellation points, add -fexceptions flag
for them, two functions _pthread_cancel_enter and _pthread_cancel_leave
are added to let thread enter and leave a cancellation point, it also
makes it possible that other functions can be cancellation points in
libraries without having to be rewritten in libthr.
2010-09-25 01:57:47 +00:00
davidxu
b0052272aa inline testcancel() into thr_cancel_leave(), because cancel_pending is
almost false, this makes a slight better branch predicting.
2010-09-24 13:01:01 +00:00
davidxu
722a516400 In most cases, cancel_point and cancel_async needn't be checked again,
because cancellation is almostly checked at cancellation points.
2010-09-24 07:52:07 +00:00
davidxu
585e6320d2 If we are at cancellation point, always work as deferred mode despite
whether asynchronous mode is turned on or not, this always gives us a
chance to decide whether thread should be canceled or not in
cancellation points.
2010-09-21 06:47:04 +00:00
davidxu
fe5567c8f1 Because atfork lock is held while forking, a thread cancellation triggered
by atfork handler is unsafe, use intenal flag no_cancel to disable it.
2010-09-19 09:03:11 +00:00
davidxu
5418a23597 Fix typo. 2010-09-19 08:55:36 +00:00
davidxu
4c94bb3829 - _Unwind_Resume function is not used, remove it.
- Use a store barrier to make sure uwl_forcedunwind is lastest thing
  other threads can see.
- Add some comments.
2010-09-19 05:42:29 +00:00
davidxu
ad24f558bd Fix a race condition when finding stack unwinding functions. 2010-09-19 05:19:47 +00:00
davidxu
b00fcaa22c add code to support stack unwinding when thread exits. note that only
defer-mode cancellation works, asynchrnous mode does not work because
it lacks of libuwind's support. stack unwinding is not enabled unless
LIBTHR_UNWIND_STACK is defined in Makefile.
2010-09-15 02:56:32 +00:00
davidxu
6be463abbb Move back IN_GCLIST flag into field tlflags, since thread list and gc list
still share same lock.
2010-09-15 01:21:30 +00:00
davidxu
b79ad9b341 Don't compare thread pointers again. 2010-09-13 11:58:42 +00:00
davidxu
95869dd2a2 Fix copy&paste problem. 2010-09-13 11:57:46 +00:00
davidxu
ac1cdddd7f Update symbol. 2010-09-13 09:23:38 +00:00
davidxu
71456632de PS_DEAD state needs not be checked because _thr_find_thread() has already
checked it.
2010-09-13 07:18:00 +00:00
davidxu
e87e922f31 Convert thread list lock from mutex to rwlock. 2010-09-13 07:03:01 +00:00
imp
6a8c774078 Merge from tbemd, with a small amount of rework:
For all libthr contexts, use ${MACHINE_CPUARCH}
for all libc contexts, use ${MACHINE_ARCH} if it exists, otherwise use
${MACHINE_CPUARCH}
Move some common code up a layer (the .PATH statement was the same in
all the arch submakefiles).

# Hope she hasn't busted powerpc64 with this...
2010-09-13 01:43:10 +00:00
davidxu
e129c18a83 Because POSIX does not allow EINTR to be returned from sigwait(),
add a wrapper for it in libc and rework the code in libthr, the
system call still can return EINTR, we keep this feature.

Discussed on: thread
Reviewed by:  jilles
2010-09-10 01:47:37 +00:00
davidxu
417820202c To avoid possible race condition, SIGCANCEL is always sent except the
thread is dead.
2010-09-08 02:18:20 +00:00
davidxu
bc33915543 Fix off-by-one error in function _thr_sigact_unload, also disable the
function, it seems some gnome application tends to crash if we
unregister sigaction automatically.
2010-09-06 03:00:54 +00:00
davidxu
f21ffb282d Remove incorrect comments, also make sure signal is
disabled when unregistering sigaction.
2010-09-01 13:22:55 +00:00
davidxu
c19c7fe99f In function __pthread_cxa_finalize(), also make code for removing
atfork handler be async-signal safe.
2010-09-01 07:09:46 +00:00
davidxu
7852e2095b pthread_atfork should acquire writer lock and protect the code
with critical region.
2010-09-01 03:55:10 +00:00
davidxu
5f00b957ae Change atfork lock from mutex to rwlock, also make mutexes used by malloc()
module private type, when private type mutex is locked/unlocked, thread
critical region is entered or leaved. These changes makes fork()
async-signal safe which required by POSIX. Note that user's atfork handler
still needs to be async-signal safe, but it is not problem of libthr, it
is user's responsiblity.
2010-09-01 03:11:21 +00:00