Commit Graph

109 Commits

Author SHA1 Message Date
Mark Murray
16fc3635f7 Make NULL a (void*)0 whereever possible, and fix the warnings(-Werror)
that this provokes. "Wherever possible" means "In the kernel OR NOT
C++" (implying C).

There are places where (void *) pointers are not valid, such as for
function pointers, but in the special case of (void *)0, agreement
settles on it being OK.

Most of the fixes were NULL where an integer zero was needed; many
of the fixes were NULL where ascii <nul> ('\0') was needed, and a
few were just "other".

Tested on: i386 sparc64
2004-03-05 08:10:19 +00:00
Peter Grehan
a95a647dcc libthr powerpc support.
Submitted by:  Suleiman Souhlal <refugee@segfaulted.com>
Tested with: most libpthread tests, Apache 'worker' MDM
2004-03-02 06:25:20 +00:00
Mike Makonnen
d4d7df5c0c Implement PThreads barriers and barrier attributes. 2004-02-19 13:51:52 +00:00
Mike Makonnen
8c18819a81 Don't wake up the thread after the signal handler
has been executed. On return from the signal handler
the call will either be restarted or EINTR will be returned,
but it will not go back to its previous state. So, it is
sufficient to simply change the state to 'running' without
actually trying to wake up the thread.
2004-02-19 13:47:12 +00:00
Mike Makonnen
097c5e8da4 Remove thr_getschedparam.c since it's contents have been moved into
thr_setschedparam.c
2004-02-18 15:59:54 +00:00
Mike Makonnen
32eaa7dddd There are consumers of rwlocks, inluding our own libc, that depend on
a PTHREAD_RWLOCK_INITIALIZER to do for rwlocks what
a similarly named symbol does for statically initialized mutexes.
This symbol was dropped in The Open Group Base Specifications Issue 6
and does not exist in IEEE Std 1003.1, 2003, but it should still be
supported for backwards compatibility.

Pointy hat: mtm
2004-02-18 15:30:10 +00:00
Mike Makonnen
b3d73b9b1e o Catch up with the mutex priority protocol fixes.
o Move pthread_getschedparam() into the same file with it's
  pthread_set* counterpart. Copyright on both files is identical.
2004-02-18 15:26:00 +00:00
Mike Makonnen
b325a92087 o Style
o Instead of checking both the passed in pointer and its value
  for NULL, only check the latter. Any caller that passes in
  a NULL pointer is obviously wrong.
2004-02-18 15:22:52 +00:00
Mike Makonnen
a561651c34 o Refactor and, among other things, get rid of insane nesting levels.
o Fix mutex priority protocols. Keep separate counts of priority
  inheritance and protection mutexes to make things easier.
  This will not have much affect since this is only the
  userland side, and the rest involves kernel scheduling.
2004-02-18 15:16:31 +00:00
Mike Makonnen
06e5becb69 Move the initialization of thread priority to a common function. 2004-02-18 15:05:56 +00:00
Mike Makonnen
0d48409fe2 Move the weak references to the top of the file to conform
to the format of other similar files in libthr.
2004-02-18 14:56:20 +00:00
Colin Percival
d623b765cf style cleanup: Remove duplicate $FreeBSD$ tags.
These files had tags after the copyright notice,
inside the comment block (incorrect, removed),
and outside the comment block (correct).

Approved by:	rwatson (mentor)
2004-02-10 20:42:33 +00:00
Daniel Eischen
518ae0c8fd Remove the band-aid (#include <time.h>). 2004-02-03 22:30:01 +00:00
Daniel Eischen
fc9579997c Add <time.h> -- bandaid to unbreak world in <semaphore.h>. 2004-02-03 15:55:30 +00:00
Mike Makonnen
4e3c587d23 Bump up the maximum number concurrent threads on x86. 2004-02-01 15:33:01 +00:00
Mike Makonnen
1baa64733c I update the rwlock code in libthr to be more standards compliant and
what do I get for my troubles? libc breaks offcourse!

Reimplement a hack (in libthr) that allows libc to use
rwlocks without initializing them first. The hack was reimplemented
so that only a private libc version of the rwlock locking functions
initializes an uninitialized rwlock. The application version will
correctly fail.
2004-01-29 12:03:17 +00:00
Mike Makonnen
98a11db62d When suspending a thread if the timeout was very short or
the system call got interrupted and the absolute timeout is
converted to a relative timeout, it may happen that we get a
negative number. In such a case, simply set the timeout to
zero so that if the event that the thread wants to wait for has
happened it can still return successfully, but if it hasn't
happened then the thread doesn't suspend indefinitely. This should
fix certain applications (including mozilla) that seem to hang
indefinitely sometimes.

Noticed and debugged by: Morten Johansen <root@morten-johansen.net>
2004-01-29 09:44:36 +00:00
Mike Makonnen
dec04f43d9 o Implement the pthread_spin_* functions in libthr.
o Man pages
2004-01-22 15:31:56 +00:00
Mike Makonnen
1c6841ae78 Refactor _pthread_mutex_init
o Simplify the logic by removing a lot of unnecesary nesting
	o Reduce the amount of local variables
	o Zero-out the allocated structure and get rid of
	  all the unnecessary setting to 0 and NULL;

Refactor _pthread_mutex_destroy
	o Simplify the logic by removing a lot of unnecesary nesting
	o No need to check pointer that the mutex attributes points
	  to. Checking passed in pointer is enough.
2004-01-19 15:00:57 +00:00
Mike Makonnen
c40bafac85 Implement reference counting of read-write locks. This uses
a list in the thread structure to keep track of the locks and
how many times they have been locked. This list is checked
on every lock and unlock. The traversal through the list is
O(n). Most applications don't hold so many locks at once that
this will become a problem. However, if it does become a problem
it might be a good idea to review this once libthr is
off probation and in the optimization cycle.
This fixes:
	o deadlock when a thread tries to recursively acquire a
	  read lock when a writer is waiting on the lock.
	o a thread could previously successfully unlock a lock it did not own
	o deadlock when a thread tries to acquire a write lock on
	  a lock it already owns for reading or writing [ this is admittedly
	  not required by POSIX, but is nice to have ]
2004-01-19 14:51:45 +00:00
Mike Makonnen
104ff764e5 Add an implementation of pthread_rwlock_timed{rd,wr}lock() to libthr with
attendant documentation.
2004-01-16 10:52:10 +00:00
Mike Makonnen
14f8ddcd08 o We are not required to initialize an invalid rwlock. So axe all that
code and simply return EINVAL (which is allowed by the standard) in
  all those pthread functions that previously initialized it.

o Refactor the pthread_rwlock_[try]rdlock() and pthread_rwlock_[try]wrlock()
  functions. They are now completeley condensed into rwlock_rdlock_common()
  and rwlock_wrlock_common(), respectively.

o If the application tries to destroy an rwlock that is currently
  held by a thread return EBUSY where it previously went ahead and
  freed all resources associated with the lock.

o Refactor _pthread_rwlock_init() to make it look (relatively) sane.

o When obtaining a read lock on an rwlock the check for whether it
  would exceed the maximum allowed read locks should happen *before*
  we obtain the lock.

o The pthread_rwlock_* functions shall *never* return EINTR, so make
  sure to requeue/resuspend the thread if it encounters such an error.

o Make a note that pthread_rwlock_unlock() needs to ensure it holds a
  lock on an rwlock it tries to unlock. It will be implemented in a
  separate commit because it requires some additional rwlock infrastructure.
2004-01-16 07:10:30 +00:00
Ruslan Ermilov
2ed59d22bd Return ENOTSUP instead of -1. 2004-01-15 16:09:58 +00:00
Mike Makonnen
2aa9de1f77 o Implement pthread_mutex_timedlock(), which does not block indefinitely on
a mutex locked by another thread.
o document it: pthread_mutex_timedlock(3)
2003-12-30 08:44:55 +00:00
Mike Makonnen
2b33fc6470 Make it possible for the library to specify a timeout value when
waiting on a locked mutex. This involves passing a struct timespec
from the pthread mutex locking interfaces all the way down to the
function that suspends the thread until the mutex is released.
The timeout is assumed to be an absolute time (i.e. not relative to
the current time).

Also, in _thread_suspend() make the passed in timespec const.
2003-12-30 08:34:57 +00:00
Doug Rabson
795a502646 Don't block SIGTRAP - it makes it hard to debug programs with gdb.
Reviewed by: mtm
2003-12-26 12:11:16 +00:00
Mike Makonnen
f2c3dd08ec Preparations to make libthr work in multi-threaded fork()ing applications.
o Remove some code duplication between _thread_init(), which is run once
  to initialize libthr and the intitial thread, and pthread_create(), which
  initializes newly created threads, into a new function called from both
  places: init_td_common()
o Move initialization of certain parts of libthr into a separate
  function. These include:
	- Active threads list and it's lock
	- Dead threads list and it's lock & condition variable
	- Naming and insertion of the initial thread into the
	  active threads list.
2003-12-26 08:16:17 +00:00
Mike Makonnen
8657fd166c Remove _giant_mutex and its associated macros. 2003-12-15 12:38:06 +00:00
Mike Makonnen
2543fd4700 Comment out most of pthread_setschedparam. Pthread priorities didn't
work before anyways, and I didn't want to fix broken code I had no
way of testing. It was necessary however, in order to get rid of GIANT_LOCK.
Pthread priorities will have to wait a little longer to get fixed.
2003-12-15 12:31:46 +00:00
Mike Makonnen
c830473999 When creating a pthread in the suspended state their were two
problems: (1) The wrong flag was being checked for in the attribute
	  (2) The pthread's state was not being set to indicate it was
	      suspended.

Noticed by: Igor Sysoev <is@rambler-co.ru>
2003-12-15 09:35:02 +00:00
Mike Makonnen
099fe19901 Doh! Lock the thread passed in by the caller, not the current thread. 2003-12-12 09:51:39 +00:00
Mike Makonnen
f318a5206c Remove uses of GIANT_LOCK and replace with appropriate thread
and thread list locks.
2003-12-11 08:34:07 +00:00
Mike Makonnen
d214f02991 Take a stab at fixing some of the macro-nightmare.
PTHREAD_NEW_STATE should work as expected now: a thread
marked PS_RUNNING will get sent a SIGTHR.
Still more cleanups necessary.
2003-12-09 11:20:01 +00:00
Mike Makonnen
8955220107 Fix the wrapper function around signals so that a signal handling
thread on one of the mutex or condition variable queues is removed
from those queues before the real signal handler is called.
2003-12-09 11:12:11 +00:00
Mike Makonnen
6fedbb4e37 Ugghh, cvs add the functions necessary to lock the global signal action
table.
2003-12-09 11:06:55 +00:00
Mike Makonnen
4a7709c540 o Add a wrapper around sigaction(2), so we can insert our own wrapper
around signals.
o Lock the process global signal action table.
2003-12-09 11:04:36 +00:00
Mike Makonnen
d63466e954 Enable cancellation points around some syscalls. 2003-12-09 11:01:09 +00:00
Mike Makonnen
a4be5b10a2 Use dynamic instead of static LDT allocation.
Approved by: re (scottl)
2003-12-02 16:00:26 +00:00
Marcel Moolenaar
ed74e02776 Relink libc_r.a, libc_r.so and libc_r_p.so from libthr to libkse.
On ia64, where there's no libc_r at all, libkse is now the default
thread library by virtue of these links.

The reasons for this change are:
1. libkse is slated to become the default thread library anyway,
2. active development and maintenance is only present for libkse,
3. GNOME and KDE, both in the process of being supported on ia64,
   work better with KSE; even on ia64.
2003-09-27 23:27:19 +00:00
Marcel Moolenaar
c24297c0f2 Implement _get_curthread and _set_curthread. We use GCCs builtin
function this, which expands to PAL calls (rduniq and wruniq).
This needs adjustment when TLS is implemented.
2003-07-24 07:51:49 +00:00
Mike Makonnen
9e222aaf7a The MD framework for libthr on alpha 2003-07-19 15:57:52 +00:00
Mike Makonnen
393441d43b When _PTHREADSINVARIANTS is defined SIGABRT is not included
in the set of signals to block.
Also, make the PANIC macro call abort() instead of simply
exiting.
2003-07-08 09:58:23 +00:00
Mike Makonnen
659045ffbf Change all instances of THR_LOCK/UNLOCK, etc to UMTX_*.
It is a more acurate description of the locks they
operate on.
2003-07-06 10:18:48 +00:00
Mike Makonnen
9644071977 There's no need for _umtxtrylock to be a separate function.
Roll it into the pre-existing macro that's used to call it.
2003-07-06 10:10:32 +00:00
Mike Makonnen
e921a3c976 _pthread_mutex_trylock() is another internal libc function that must block
signals.
2003-07-03 13:28:53 +00:00
Mike Makonnen
f493d09ae7 Begin making libthr async signal safe.
Create a private, single underscore, version of pthread_mutex_unlock for libc.
pthread_mutex_lock already has one. These versions are different from the
ones that applications will link against because they block all signals
from the time a call to lock the mutex is made until it is successfully
unlocked.
2003-07-02 02:05:23 +00:00
Mike Makonnen
745a4a9ef8 Do not attempt to reque a thread on a mutex queue. It may be that
a thread receives a spurious wakeup from sigtimedwait(), so make sure
that the call to the queueing code is called only once before entering
the loop (not in the loop). This should fix some fatal errors people
are seeing with messages stating the thread is already on the mutex queue.
These errors may still be triggered from signal handlers; however, since
that part of the code is not locked down yet.
2003-07-01 15:52:09 +00:00
Ruslan Ermilov
0b3cbc5c38 Axe AINC.
Submitted by:	bde
2003-07-01 15:07:01 +00:00
Mike Makonnen
fadd82e367 Catchup with _thread_suspend() changes. 2003-06-30 12:35:31 +00:00
Mike Makonnen
dbc6f4c07d Sweep through pthread locking and use the new locking primitives for
libthr.
2003-06-29 23:51:04 +00:00