summaryrefslogtreecommitdiff
path: root/src/time
AgeCommit message (Collapse)AuthorFilesLines
2013-05-05fix incorrect clock tick scaling in fallback case of clock()Rich Felker1-1/+1
since CLOCKS_PER_SEC is 1000000 (required by XSI) and the times syscall reports values in 1/100 second units (Linux), the correct scaling factor is 10000, not 100. note that only ancient kernels which lack clock_gettime are affected.
2013-05-05do not interpret errors in return value of times() syscallRich Felker1-1/+1
all return values are valid, and on 32-bit systems, values that look like errors can and will occur. since the only actual error this function could return is EFAULT, and it is only returnable when the application has invoked undefined behavior, simply ignore the possibility that the return value is actually an error code.
2013-04-06silence nonsensical warnings in timer_createRich Felker1-2/+2
2013-04-02__time_to_tm: initialize tm_zone and tm_gmtoffrofl0r1-0/+2
2013-03-26remove __SYSCALL_SSLEN arch macro in favor of using public _NSIGRich Felker1-1/+1
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.
2013-02-02make some arrays constrofl0r1-1/+1
this way they'll go into .rodata, decreasing memory pressure.
2013-01-26fix tm_to_time logic for number of days in novemberRich Felker1-1/+1
report/patch by Hiltjo Posthuma <hiltjo@codemadness.org>
2012-11-08clean up sloppy nested inclusion from pthread_impl.hRich Felker1-0/+1
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).
2012-09-29more close-on-exec fixes, mostly using new "e" flag to fopenRich Felker1-1/+1
2012-09-06use restrict everywhere it's required by c99 and/or posix 2008Rich Felker10-11/+11
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.
2012-08-09fix (hopefully) all hard-coded 8's for kernel sigset_t sizeRich Felker1-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-06-13add timegm function (inverse of gmtime), nonstandardRich Felker1-0/+9
2012-05-24linux deprecated SYS_utime on some archs, so use SYS_utimes insteadRich Felker1-1/+8
the old code could be kept for cases where SYS_utime is available, but it's not really worth the ifdef ugliness. and better to avoid deprecated stuff just in case the kernel devs ever get crazy enough to start removing it from archs where it was part of the ABI and breaking static bins...
2012-04-24ditch the priority inheritance locks; use malloc's version of lockRich Felker1-3/+3
i did some testing trying to switch malloc to use the new internal lock with priority inheritance, and my malloc contention test got 20-100 times slower. if priority inheritance futexes are this slow, it's simply too high a price to pay for avoiding priority inversion. maybe we can consider them somewhere down the road once the kernel folks get their act together on this (and perferably don't link it to glibc's inefficient lock API)... as such, i've switch __lock to use malloc's implementation of lightweight locks, and updated all the users of the code to use an array with a waiter count for their locks. this should give optimal performance in the vast majority of cases, and it's simple. malloc is still using its own internal copy of the lock code because it seems to yield measurably better performance with -O3 when it's inlined (20% or more difference in the contention stress test).
2012-03-02remove debug cruft that was left in getdateRich Felker1-2/+0
2012-03-02first try at implementing getdate functionRich Felker1-0/+47
2012-03-02fix bugs in strptime handling of string day/month names, literalsRich Felker1-0/+2
2012-02-28implement wcsftime functionRich Felker1-0/+32
2011-09-26cleanup various minor issues reported by nszRich Felker1-1/+2
the changes to syscall_ret are mostly no-ops in the generated code, just cleanup of type issues and removal of some implementation-defined behavior. the one exception is the change in the comparison value, which is fixed so that 0xf...f000 (which in principle could be a valid return value for mmap, although probably never in reality) is not treated as an error return.
2011-09-16fix assumptions that char is signedRich Felker1-2/+2
2011-09-14remove incorrectly-made-visible internal dst offset variableRich Felker1-1/+0
2011-09-05strptime: fix use of uninitialized dest field in converting integerRich Felker1-1/+1
2011-08-16partially working strptimeRich Felker1-148/+149
it's missing at least: - derived fields - week numbers - short year (without century) support - locale modifiers
2011-08-13fix missing include in last commitRich Felker1-0/+1
2011-08-13fix clock() functionRich Felker1-2/+7
it previously was returning the pseudo-monotonic-realtime clock returned by times() rather than process cputime. it also violated C namespace by pulling in times(). we now use clock_gettime() if available because times() has ridiculously bad resolution. still provide a fallback for ancient kernels without clock_gettime.
2011-08-12more efficient signal blocking for timer threadsRich Felker1-4/+4
due to the barrier, it's safe just to block signals in the new thread, rather than blocking and unblocking in the parent thread.
2011-08-11normal exit from timer thread should run dtors, restore cancel stateRich Felker1-1/+1
2011-08-11block signals in timer threadsRich Felker1-0/+4
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.
2011-08-07use weak aliase rather than weak reference for vdso clock_gettimeRich Felker1-8/+12
this works around pcc's lack of working support for weak references, and in principle is nice because it gets us back to the stage where the only weak symbol feature we use is weak aliases, nothing else. having fewer dependencies on fancy linker features is a good thing.
2011-07-24workaround for gcc's optimizer breaking dynamic symbol resolutionRich Felker1-1/+2
2011-07-24const correctness on function pointerRich Felker1-1/+1
2011-07-23some preliminaries for vdso clock supportRich Felker3-7/+35
these changes also make it so clock_gettime(CLOCK_REALTIME, &ts) works even on pre-2.6 kernels, emulated via the gettimeofday syscall. there is no cost for the fallback check, as it falls under the error case that already must be checked for storing the error code in errno, but which would normally be hidden inside __syscall_ret.
2011-06-13remove old useless timezone.s file (unused)Rich Felker1-27/+0
2011-06-06use volatile pointers for intentional-crash code.Rich Felker1-1/+1
2011-05-07optimize compound-literal sigset_t's not to contain useless hurd bitsRich Felker1-1/+1
2011-05-07overhaul implementation-internal signal protectionsRich Felker1-2/+1
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.
2011-04-17overhaul pthread cancellationRich Felker2-11/+2
this patch improves the correctness, simplicity, and size of cancellation-related code. modulo any small errors, it should now be completely conformant, safe, and resource-leak free. the notion of entering and exiting cancellation-point context has been completely eliminated and replaced with alternative syscall assembly code for cancellable syscalls. the assembly is responsible for setting up execution context information (stack pointer and address of the syscall instruction) which the cancellation signal handler can use to determine whether the interrupted code was in a cancellable state. these changes eliminate race conditions in the previous generation of cancellation handling code (whereby a cancellation request received just prior to the syscall would not be processed, leaving the syscall to block, potentially indefinitely), and remedy an issue where non-cancellable syscalls made from signal handlers became cancellable if the signal handler interrupted a cancellation point. x86_64 asm is untested and may need a second try to get it right.
2011-04-14use a separate signal from SIGCANCEL for SIGEV_THREAD timersRich Felker1-7/+25
otherwise we cannot support an application's desire to use asynchronous cancellation within the callback function. this change also slightly debloats pthread_create.c.
2011-04-09run pthread tsd destructors when a timer thread pretends to exitRich Felker1-0/+6
2011-04-09greatly improve SIGEV_THREAD timersRich Felker2-15/+20
calling pthread_exit from, or pthread_cancel on, the timer callback thread will no longer destroy the timer.
2011-04-06consistency: change all remaining syscalls to use SYS_ rather than __NR_ prefixRich Felker3-3/+3
2011-04-06fix signal-based timers with null sigevent argumentRich Felker5-28/+19
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.)
2011-04-03timer threads should sleep and stay asleep... a long timeRich Felker1-1/+1
2011-04-03revert to deleting kernel-level timer from cancellation handlerRich Felker2-7/+11
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.
2011-04-03simplify calling of timer signal handlerRich Felker1-3/+1
2011-03-30avoid all malloc/free in timer creation/destructionRich Felker5-29/+20
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.
2011-03-30optimize timer creation and possibly protect against some minor racesRich Felker1-14/+19
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.
2011-03-29reorder timer initialization so that timer_create does not depend on freeRich Felker2-9/+17
this allows small programs which only create times, but never delete them, to use simple_malloc instead of the full malloc.
2011-03-29implement POSIX timersRich Felker5-0/+143
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.
2011-03-24overhaul cancellation to fix resource leaks and dangerous behavior with signalsRich Felker1-0/+1
this commit addresses two issues: 1. a race condition, whereby a cancellation request occurring after a syscall returned from kernelspace but before the subsequent CANCELPT_END would cause cancellable resource-allocating syscalls (like open) to leak resources. 2. signal handlers invoked while the thread was blocked at a cancellation point behaved as if asynchronous cancellation mode wer in effect, resulting in potentially dangerous state corruption if a cancellation request occurs. the glibc/nptl implementation of threads shares both of these issues. with this commit, both are fixed. however, cancellation points encountered in a signal handler will not be acted upon if the signal was received while the thread was already at a cancellation point. they will of course be acted upon after the signal handler returns, so in real-world usage where signal handlers quickly return, it should not be a problem. it's possible to solve this problem too by having sigaction() wrap all signal handlers with a function that uses a pthread_cleanup handler to catch cancellation, patch up the saved context, and return into the cancellable function that will catch and act upon the cancellation. however that would be a lot of complexity for minimal if any benefit...