Commit Graph

173 Commits

Author SHA1 Message Date
stefanf
cfb22f4f3d Include needed headers that were obtained through <pthread.h>. Sort headers
while here.
2005-09-01 15:21:23 +00:00
stefanf
ebb9dbd6dc - Prefix MUTEX_TYPE_MAX with PTHREAD_ to avoid namespace pollution.
- Remove the macros MUTEX_TYPE_FAST and MUTEX_TYPE_COUNTING_FAST.

OK'ed by:	deischen
2005-08-19 21:31:42 +00:00
deischen
73b7ac977f Add usleep to the map files.
Noticed by:	davidxu
2005-08-03 01:54:52 +00:00
deischen
4f1d7c9b66 Add a cancellation point for usleep().
While here, fix sleep() so that it is also a cancellation point (a
missing weak reference prevented that).
2005-08-03 00:47:31 +00:00
davidxu
7c1008d53a Cast to uintptr_t to avoid compiler warning, it was broken by
the recent atomic_ptr() change.
2005-07-28 03:34:54 +00:00
kensmith
0b23937d0d Bump the shared library version number of all libraries that have not
been bumped since RELENG_5.

Reviewed by:	ru
Approved by:	re (not needed for commit check but in principle...)
2005-07-22 17:19:05 +00:00
davidxu
85cf3eca78 Fix off-by-one nanosecond bug in macro TIMESPEC_ADD.
Reviewed by: deischen
Approved by: re (dwhite)
MFC after  : 4 days
2005-06-22 22:38:56 +00:00
ru
2b4d34d46b Markup fixes.
Approved by:	re
2005-06-16 19:01:07 +00:00
rwatson
5fa821c42d Remove incorrect BUGS entry: libthr does support process-scope thread
scheduling.

MFC after:	1 week
Submitted by:	davidxu
Approved by:	re (scottl)
2005-06-15 15:21:10 +00:00
rwatson
802ab290dd Add a stub libthr(3) man page to document what it is and why, as well as
to point at libmap.conf(5).  This will help answer questions about what
and why it is, although not in great detail.

Approved by:	re (scottl)
MFC after:	1 week
MFC note:	When MFC'd, don't MFC mention of work not yet MFC'd.
2005-06-11 15:27:56 +00:00
davidxu
83676d6e56 Remove COMPAT_32BIT, it is no longer needed. 2005-04-27 01:29:03 +00:00
davidxu
60c6c7b8b2 Remove unused variable. 2005-04-23 03:34:43 +00:00
davidxu
adb328dcef Now libthr only uses GDT based tls on i386. using LDT can only increase
clock cycles and has 8191 threads limitation.
2005-04-23 03:31:59 +00:00
davidxu
ebb5b375ac Use thr_new syscall to create a new thread, obscure context operations
is no longer needed.
2005-04-23 02:48:59 +00:00
davidxu
4c8a72d3c0 Add i386_get_gsbase, i386_set_gsbase since old libc doesn't have the
functions, otherwise user ports have to be rebuilt.
2005-04-23 02:14:38 +00:00
peter
09dd25461d Adapt the libpthread patch for using i386_set_gsbase() to libthr. 2005-04-14 00:44:07 +00:00
davidxu
6d18f49aa2 Conditionally report initial thread event. 2005-04-12 03:13:49 +00:00
davidxu
fe159b7e4f Add missing event reporting code. 2005-04-12 03:08:11 +00:00
davidxu
9a450de5e5 Add debugger event reporting support, current only TD_CREATE and TD_DEATH
events are reported.
2005-04-12 03:00:28 +00:00
cognet
e8d51f9d09 Use the new atomic_cmpset_32(). 2005-04-07 22:06:05 +00:00
davidxu
70cc2b7368 Adjust hash function for smaller pthread structure size. 2005-04-07 06:09:17 +00:00
davidxu
7965a0881a Remove unique id field which is no longer used by debugger. 2005-04-06 13:57:31 +00:00
davidxu
a537d608eb Remove debug symbol from installed library, one can always
use compiled version in libthr directory.
2005-04-06 13:48:11 +00:00
davidxu
d33a2129b5 Pass exact number of threads. 2005-04-04 23:43:53 +00:00
davidxu
2d78186f5f Export pthread_condattr_getclock, pthread_condattr_setclock. 2005-04-03 23:52:29 +00:00
davidxu
9e6bcdddb8 Import my recent 1:1 threading working. some features improved includes:
1. fast simple type mutex.
 2. __thread tls works.
 3. asynchronous cancellation works ( using signal ).
 4. thread synchronization is fully based on umtx, mainly, condition
    variable and other synchronization objects were rewritten by using
    umtx directly. those objects can be shared between processes via
    shared memory, it has to change ABI which does not happen yet.
 5. default stack size is increased to 1M on 32 bits platform, 2M for
    64 bits platform.
As the result, some mysql super-smack benchmarks show performance is
improved massivly.

Okayed by: jeff, mtm, rwatson, scottl
2005-04-02 01:20:00 +00:00
marcus
08440d6d16 Increase the default stacksizes:
32-bit		64-bit
main thread	2 MB		4 MB
other threads	1 MB		2 MB

Approved by:	mtm
Adapted from:	libpthread
2005-03-06 07:56:18 +00:00
peter
90de4caa54 Fix inverted #ifdef that I added. Who had the pointy hat last?
Submitted by:  kan
2004-12-06 20:41:09 +00:00
das
6a48ffb81b Don't include sys/user.h merely for its side-effect of recursively
including other headers.
2004-11-27 06:51:39 +00:00
peter
168e06dbcc Use the recently exposed fs/gs set functions when compiling libthr to
run as a 32 bit support library for an amd64 kernel.  32 bit consumers of
libthr have zero chance of running on an amd64 kernel since we don't
implement the i386_set_ldt() family of functions.  Note that this commit
doesn't make it actually work, it just removes one more obstacle.
2004-11-06 03:30:53 +00:00
ru
1edab47bcf For variables that are only checked with defined(), don't provide
any fake value.
2004-10-24 15:33:08 +00:00
mtm
20a1c9b1e5 1. Now that it's a thread's state is changed from within the kernel, where
no userland locks are heald, the dead thread lock can no longer protect
   access to it. Therefore, instead of using an if (!dead)...else clause
   after walking the active threads list test the thread pointer before
   deciding not to walk the dead threads list. If the thread pointer is null
   it means it was not found in the active threads list and the dead threads
   list should be checked.

2. Do not free the stack of a thread that is not marked dead. This is the
   2nd and final part of eliminating the race to free a thread's stack.

MFC after: 3 days
2004-10-13 11:42:20 +00:00
mtm
97fe5d7061 Remove a reference to a non-existent syscall: _thr_exit(). The
actual name is thr_exit(). How this ever worked is beyond me.
2004-10-08 14:48:02 +00:00
mtm
b48e41f9ef Close a race between a thread exiting and the freeing of it's stack.
After some discussion the best option seems to be to signal the thread's
death from within the kernel. This requires that thr_exit() take an
argument.

Discussed with: davidxu, deischen, marcel
MFC after: 3 days
2004-10-06 14:23:00 +00:00
mtm
2c913826a0 Remove vestiges of libthr's signal mangling past. This fixes that last
known problem with mysql on libthr: not being able to kill mysqld.
2004-09-22 18:51:16 +00:00
mtm
a5d62e6a64 The SUSv3 function say that the affected functions MAY FAIL, if the
specified mutex is invalid. In spec parlance 'MAY FAIL' means it's
up to the implementor. So, remove the check for NULL pointers for two
reasons:
	1. A mutex may be invalid without necessarily being NULL.
	2. If the pointer to the mutex is NULL core-dumping in the
	   vicinity of the problem is much much much better than failing
	   in some other part of the code (especially when the application
	   doesn't check the return value of the function that you oh so
	   helpfully set to EINVAL).
2004-09-22 16:53:23 +00:00
mtm
a9c80017cb Implement cancellation points in libc interfaces, as specified by POSIX. 2004-09-16 13:55:46 +00:00
davidxu
dbcf36113d Adjust code to support AMD64, on AMD64, thread needs to set fsbase by
itself before it can execute any other code, so new thread should be
created with all signals are masked until after fsbase is set.
2004-08-19 23:49:04 +00:00
davidxu
c02863a4dd Add AMD64 support code. 2004-08-19 23:41:12 +00:00
dfr
ba80c52dc3 Add rtld-elf to the include path for the rtld to pthread TLS interface. 2004-08-15 21:51:18 +00:00
dfr
fb318ab4c6 Add TLS support for libthr on i386. 2004-08-15 16:21:30 +00:00
mtm
1d060bde99 o Assertions to catch that stuff that shouldn't happen is not happening.
o In the rwlock code: move a duplicated check inside an if..else to after
  the if...else clause.
o When initializing a static rwlock move the initialization check
  inside the lock.
o In thr_setschedparam.c: When breaking out of the trylock...retry if busy
  loop make sure to reset the mtx pointer to null if the mutex is nolonger
  in a queue.
2004-07-30 17:13:00 +00:00
marcel
c42ca27732 Define _libthr_debug for use by libthread_db. 2004-07-18 04:23:30 +00:00
marcel
d2941c8f85 Record the offset of thr_id in the thread structure. Required for
debugging.
2004-07-04 19:07:07 +00:00
marcel
92a2abad32 Change the thread ID (thr_id_t) used for 1:1 threading from being a
pointer to the corresponding struct thread to the thread ID (lwpid_t)
assigned to that thread. The primary reason for this change is that
libthr now internally uses the same ID as the debugger and the kernel
when referencing to a kernel thread. This allows us to implement the
support for debugging without additional translations and/or mappings.

To preserve the ABI, the 1:1 threading syscalls, including the umtx
locking API have not been changed to work on a lwpid_t. Instead the
1:1 threading syscalls operate on long and the umtx locking API has
not been changed except for the contested bit. Previously this was
the least significant bit. Now it's the most significant bit. Since
the contested bit should not be tested by userland, this change is
not expected to be visible. Just to be sure, UMTX_CONTESTED has been
removed from <sys/umtx.h>.

Reviewed by: mtm@
ABI preservation tested on: i386, ia64
2004-07-02 00:40:07 +00:00
mtm
7db21ef94b When a thread is created suspended have libthr suspend it explicitly
instead of asking the kernel to do it when we create the thread.
2004-06-30 15:57:36 +00:00
mtm
abcb0c4fd2 Implement pthread_atfork in libthr. This is mostly from deichen's
work in libpthread.

Submitted by: Dan Nelson <dnelson@allantgroup.com>
2004-06-27 10:01:35 +00:00
mtm
d2788deb74 In the case that the global thread list is being re-initialized after
a fork, make sure that the current thread isn't detached and freed. As
a consequence the thread should be inserted into the head of the
active list only once (in the beginning).
2004-06-27 09:53:06 +00:00
mtm
bd98150e60 Make libthr async-signal-safe without costly signal masking. The guidlines I
followed are: Only 3 functions (pthread_cancel, pthread_setcancelstate,
pthread_setcanceltype) are required to be async-signal-safe by POSIX. None of
the rest of the pthread api is required to be async-signal-safe. This means
that only the three mentioned functions are safe to use from inside
signal handlers.
However, there are certain system/libc calls that are
cancellation points that a caller may call from within a signal handler,
and since they are cancellation points calls have to be made into libthr
to test for cancellation and exit the thread if necessary. So, the
cancellation test and thread exit code paths must be async-signal-safe
as well. A summary of the changes follows:

o Almost all of the code paths that masked signals, as well as locking the
  pthread structure now lock only the pthread structure.
o Signals are masked (and left that way) as soon as a thread enters
  pthread_exit().
o The active and dead threads locks now explicitly require that signals
  are masked.
o Access to the isdead field of the pthread structure is protected by both
  the active and dead list locks for writing. Either one is sufficient for
  reading.
o The thread state and type fields have been combined into one three-state
  switch to make it easier to read without requiring a lock. It doesn't need
  a lock for writing (and therefore for reading either) because only the
  current thread can write to it and it is an integer value.
o The thread state field of the pthread structure has been eliminated. It
  was an unnecessary field that mostly duplicated the flags field, but
  required additional locking that would make a lot more code paths require
  signal masking. Any truly unique values (such as PS_DEAD) have been
  reborn as separate members of the pthread structure.
o Since the mutex and condvar pthread functions are not async-signal-safe
  there is no need to muck about with the wait queues when handling
  a signal ...
o ... which also removes the need for wrapping signal handlers and sigaction(2).
o The condvar and mutex async-cancellation code had to be revised as a result
  of some of these changes, which resulted in semi-unrelated changes which
  would have been difficult to work on as a separate commit, so they are
  included as well.

The only part of the changes I am worried about is related to locking for
the pthread joining fields. But, I will take a closer look at them once this
mega-patch is committed.
2004-05-20 12:06:16 +00:00
mtm
0a2785a445 q§ 2004-05-20 11:55:04 +00:00