summaryrefslogtreecommitdiff
path: root/src/thread/pthread_self.c
AgeCommit message (Collapse)AuthorLines
2012-08-09fix (hopefully) all hard-coded 8's for kernel sigset_t sizeRich Felker-1/+2
some minor changes to how hard-coded sets for thread-related purposes are handled were also needed, since the old object sizes were not necessarily sufficient. things have gotten a bit ugly in this area, and i think a cleanup is in order at some point, but for now the goal is just to get the code working on all supported archs including mips, which was badly broken by linux rejecting syscalls with the wrong sigset_t size.
2012-05-25ensure pthread-internal signals are unblocked before threads are usedRich Felker-0/+1
if the process started with these signals blocked, cancellation could fail or setxid could deadlock. there is no way to globally unblock them after threads have been created. by unblocking them in the pthread_self initialization for the main thread, we ensure that they're unblocked before any other threads are created and also outside of any signal handler context (sigaction initialized pthread_self), which is important so that return from a signal handler won't re-block them.
2012-02-27work around "signal loses thread pointer" issue with "approach 2"Rich Felker-2/+3
this was discussed on the mailing list and no consensus on the preferred solution was reached, so in anticipation of a release, i'm just committing a minimally-invasive solution that avoids the problem by ensuring that multi-threaded-capable programs will always have initialized the thread pointer before any signal handler can run. in the long term we may switch to initializing the thread pointer at program start time whenever the program has the potential to access any per-thread data.
2011-09-13remove some stray trailing space charactersRich Felker-1/+1
2011-08-06simplify multi-threaded errno, eliminate useless function pointerRich Felker-7/+2
2011-07-30add proper fuxed-based locking for stdioRich Felker-0/+2
previously, stdio used spinlocks, which would be unacceptable if we ever add support for thread priorities, and which yielded pathologically bad performance if an application attempted to use flockfile on a key file as a major/primary locking mechanism. i had held off on making this change for fear that it would hurt performance in the non-threaded case, but actually support for recursive locking had already inflicted that cost. by having the internal locking functions store a flag indicating whether they need to perform unlocking, rather than using the actual recursive lock counter, i was able to combine the conditionals at unlock time, eliminating any additional cost, and also avoid a nasty corner case where a huge number of calls to ftrylockfile could cause deadlock later at the point of internal locking. this commit also fixes some issues with usage of pthread_self conflicting with __attribute__((const)) which resulted in crashes with some compiler versions/optimizations, mainly in flockfile prior to pthread_create.
2011-04-20fix minor bugs due to incorrect threaded-predicate semanticsRich Felker-4/+2
some functions that should have been testing whether pthread_self() had been called and initialized the thread pointer were instead testing whether pthread_create() had been called and actually made the program "threaded". while it's unlikely any mismatch would occur in real-world problems, this could have introduced subtle bugs. now, we store the address of the main thread's thread descriptor in the libc structure and use its presence as a flag that the thread register is initialized. note that after fork, the calling thread (not necessarily the original main thread) is the new main thread.
2011-04-17debloat: use __syscall instead of syscall where possibleRich Felker-1/+1
don't waste time (and significant code size due to function call overhead!) setting errno when the result of a syscall does not matter or when it can't fail.
2011-04-17optimize cancellation enable/disable codeRich Felker-0/+1
the goal is to be able to use pthread_setcancelstate internally in the implementation, whenever a function might want to use functions which are cancellation points but avoid becoming a cancellation point itself. i could have just used a separate internal function for temporarily inhibiting cancellation, but the solution in this commit is better because (1) it's one less implementation-specific detail in functions that need to use it, and (2) application code can also get the same benefit. previously, pthread_setcancelstate dependend on pthread_self, which would pull in unwanted thread setup overhead for non-threaded programs. now, it temporarily stores the state in the global libc struct if threads have not been initialized, and later moves it if needed. this way we can instead use __pthread_self, which has no dependencies and assumes that the thread register is already valid.
2011-04-01use bss instead of mmap for main thread's pthread thread-specific dataRich Felker-9/+3
this simplifies code and removes a failure case
2011-03-20global cleanup to use the new syscall interfaceRich Felker-1/+1
2011-03-09optimize pthread initializationRich Felker-2/+2
the set_tid_address returns the tid (which is also the pid when called from the initial thread) so there is no need to make a separate syscall to get pid/tid.
2011-03-03optimize POSIX TSD for fast pthread_getspecificRich Felker-0/+11
2011-02-15finish unifying thread register handling in preparation for portingRich Felker-9/+3
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker-0/+39