#
a7f18a55 |
|
03-Aug-2013 |
Rich Felker <dalias@aerifal.cx> |
have new timer threads unblock their own SIGTIMER unblocking it in the pthread_once init function is not sufficient, since multiple threads, some of them with the signal blocked, could already exist before this is called; timers started from such threads would be non-functional.
|
#
7c6c2906 |
|
03-Aug-2013 |
Rich Felker <dalias@aerifal.cx> |
add system for resetting TLS to initial values this is needed for reused threads in the SIGEV_THREAD timer notification system, and could be reused elsewhere in the future if needed, though it should be refactored for such use. for static linking, __init_tls.c is simply modified to export the TLS info in a structure with external linkage, rather than using statics. this perhaps makes the code more clear, since the statics were poorly named for statics. the new __reset_tls.c is only linked if it is used. for dynamic linking, the code is in dynlink.c. sharing code with __copy_tls is not practical since __reset_tls must also re-zero thread-local bss.
|
#
7356c255 |
|
03-Aug-2013 |
Rich Felker <dalias@aerifal.cx> |
fix multiple bugs in SIGEV_THREAD timers 1. the thread result field was reused for storing a kernel timer id, but would be overwritten if the application code exited or cancelled the thread. 2. low pointer values were used as the indicator that the timer id is a kernel timer id rather than a thread id. this is not portable, as mmap may return low pointers on some conditions. instead, use the fact that pointers must be aligned and kernel timer ids must be non-negative to map pointers into the negative integer space. 3. signals were not blocked until after the timer thread started, so a race condition could allow a signal handler to run in the timer thread when it's not supposed to exist. this is mainly problematic if the calling thread was the only thread where the signal was unblocked and the signal handler assumes it runs in that thread.
|
#
cc11b422 |
|
06-Apr-2013 |
Rich Felker <dalias@aerifal.cx> |
silence nonsensical warnings in timer_create
|
#
ccc7b4c3 |
|
26-Mar-2013 |
Rich Felker <dalias@aerifal.cx> |
remove __SYSCALL_SSLEN arch macro in favor of using public _NSIG the issue at hand is that many syscalls require as an argument the kernel-ABI size of sigset_t, intended to allow the kernel to switch to a larger sigset_t in the future. previously, each arch was defining this size in syscall_arch.h, which was redundant with the definition of _NSIG in bits/signal.h. as it's used in some not-quite-portable application code as well, _NSIG is much more likely to be recognized and understood immediately by someone reading the code, and it's also shorter and less cluttered. note that _NSIG is actually 65/129, not 64/128, but the division takes care of throwing away the off-by-one part.
|
#
efd4d87a |
|
08-Nov-2012 |
Rich Felker <dalias@aerifal.cx> |
clean up sloppy nested inclusion from pthread_impl.h this mirrors the stdio_impl.h cleanup. one header which is not strictly needed, errno.h, is left in pthread_impl.h, because since pthread functions return their error codes rather than using errno, nearly every single pthread function needs the errno constants. in a few places, rather than bringing in string.h to use memset, the memset was replaced by direct assignment. this seems to generate much better code anyway, and makes many functions which were previously non-leaf functions into leaf functions (possibly eliminating a great deal of bloat on some platforms where non-leaf functions require ugly prologue and/or epilogue).
|
#
400c5e5c |
|
06-Sep-2012 |
Rich Felker <dalias@aerifal.cx> |
use restrict everywhere it's required by c99 and/or posix 2008 to deal with the fact that the public headers may be used with pre-c99 compilers, __restrict is used in place of restrict, and defined appropriately for any supported compiler. we also avoid the form [restrict] since older versions of gcc rejected it due to a bug in the original c99 standard, and instead use the form *restrict.
|
#
2f437040 |
|
09-Aug-2012 |
Rich Felker <dalias@aerifal.cx> |
fix (hopefully) all hard-coded 8's for kernel sigset_t size 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.
|
#
b1a7102d |
|
11-Aug-2011 |
Rich Felker <dalias@aerifal.cx> |
more efficient signal blocking for timer threads due to the barrier, it's safe just to block signals in the new thread, rather than blocking and unblocking in the parent thread.
|
#
8b625e45 |
|
11-Aug-2011 |
Rich Felker <dalias@aerifal.cx> |
normal exit from timer thread should run dtors, restore cancel state
|
#
c5168071 |
|
11-Aug-2011 |
Rich Felker <dalias@aerifal.cx> |
block signals in timer threads if a timer thread leaves signals unblocked, any future attempt by the main thread to prevent the process from being terminated by blocking signals will fail, since the signal can still be delivered to the timer thread.
|
#
4c4e22d7 |
|
07-May-2011 |
Rich Felker <dalias@aerifal.cx> |
optimize compound-literal sigset_t's not to contain useless hurd bits
|
#
99b8a25e |
|
07-May-2011 |
Rich Felker <dalias@aerifal.cx> |
overhaul implementation-internal signal protections the new approach relies on the fact that the only ways to create sigset_t objects without invoking UB are to use the sig*set() functions, or from the masks returned by sigprocmask, sigaction, etc. or in the ucontext_t argument to a signal handler. thus, as long as sigfillset and sigaddset avoid adding the "protected" signals, there is no way the application will ever obtain a sigset_t including these bits, and thus no need to add the overhead of checking/clearing them when sigprocmask or sigaction is called. note that the old code actually *failed* to remove the bits from sa_mask when sigaction was called. the new implementations are also significantly smaller, simpler, and faster due to ignoring the useless "GNU HURD signals" 65-1024, which are not used and, if there's any sanity in the world, never will be used.
|
#
016a5dc1 |
|
13-Apr-2011 |
Rich Felker <dalias@aerifal.cx> |
use a separate signal from SIGCANCEL for SIGEV_THREAD timers otherwise we cannot support an application's desire to use asynchronous cancellation within the callback function. this change also slightly debloats pthread_create.c.
|
#
2063c4ca |
|
09-Apr-2011 |
Rich Felker <dalias@aerifal.cx> |
run pthread tsd destructors when a timer thread pretends to exit
|
#
82171d6a |
|
09-Apr-2011 |
Rich Felker <dalias@aerifal.cx> |
greatly improve SIGEV_THREAD timers calling pthread_exit from, or pthread_cancel on, the timer callback thread will no longer destroy the timer.
|
#
cd3bb384 |
|
06-Apr-2011 |
Rich Felker <dalias@aerifal.cx> |
fix signal-based timers with null sigevent argument since timer_create is no longer allocating a structure for the timer_t and simply using the kernel timer id, it was impossible to specify the timer_t as the argument to the signal handler. the solution is to pass the null sigevent pointer on to the kernel, rather than filling it in userspace, so that the kernel does the right thing. however, that precludes the clever timerid-versus-threadid encoding we were doing. instead, just assume timerids are below 1M and thread pointers are above 1M. (in perspective: timerids are sequentially allocated and seem limited to 32k, and thread pointers are at roughly 3G.)
|
#
6e9ed66d |
|
02-Apr-2011 |
Rich Felker <dalias@aerifal.cx> |
timer threads should sleep and stay asleep... a long time
|
#
6f1414e1 |
|
02-Apr-2011 |
Rich Felker <dalias@aerifal.cx> |
revert to deleting kernel-level timer from cancellation handler this is necessary in order to avoid breaking timer_getoverrun in the last run of the timer event handler, if it has not yet finished.
|
#
f01d3518 |
|
02-Apr-2011 |
Rich Felker <dalias@aerifal.cx> |
simplify calling of timer signal handler
|
#
3990c5c6 |
|
30-Mar-2011 |
Rich Felker <dalias@aerifal.cx> |
avoid all malloc/free in timer creation/destruction instead of allocating a userspace structure for signal-based timers, simply use the kernel timer id. we use the fact that thread pointers will always be zero in the low bit (actually more) to encode integer timerid values as pointers. also, this change ensures that the timer_destroy syscall has completed before the library timer_destroy function returns, in case it matters.
|
#
b8be64c4 |
|
29-Mar-2011 |
Rich Felker <dalias@aerifal.cx> |
optimize timer creation and possibly protect against some minor races the major idea of this patch is not to depend on having the timer pointer delivered to the signal handler, and instead use the thread pointer to get the callback function address and argument. this way, the parent thread can make the timer_create syscall while the child thread is starting, and it should never have to block waiting for the barrier.
|
#
68063001 |
|
29-Mar-2011 |
Rich Felker <dalias@aerifal.cx> |
reorder timer initialization so that timer_create does not depend on free this allows small programs which only create times, but never delete them, to use simple_malloc instead of the full malloc.
|
#
80c4dcd2 |
|
29-Mar-2011 |
Rich Felker <dalias@aerifal.cx> |
implement POSIX timers this implementation is superior to the glibc/nptl implementation, in that it gives true realtime behavior. there is no risk of timer expiration events being lost due to failed thread creation or failed malloc, because the thread is created as time creation time, and reused until the timer is deleted.
|