diff options
Diffstat (limited to 'src/time')
| -rw-r--r-- | src/time/__tz.c | 20 | ||||
| -rw-r--r-- | src/time/__utc.c | 3 | ||||
| -rw-r--r-- | src/time/strptime.c | 13 | ||||
| -rw-r--r-- | src/time/time_impl.h | 1 | ||||
| -rw-r--r-- | src/time/timer_create.c | 29 |
5 files changed, 50 insertions, 16 deletions
diff --git a/src/time/__tz.c b/src/time/__tz.c index c34b3eb7..cfce268e 100644 --- a/src/time/__tz.c +++ b/src/time/__tz.c @@ -24,7 +24,6 @@ weak_alias(__tzname, tzname); static char std_name[TZNAME_MAX+1]; static char dst_name[TZNAME_MAX+1]; -const char __utc[] = "UTC"; static int dst_off; static int r0[5], r1[5]; @@ -437,3 +436,22 @@ const char *__tm_to_tzname(const struct tm *tm) UNLOCK(lock); return p; } + +int __tzname_to_isdst(const char *restrict *s) +{ + size_t len; + int isdst = -1; + LOCK(lock); + if (tzname[0] && !strncmp(*s, tzname[0], len = strlen(tzname[0]))) { + isdst = 0; + *s += len; + } else if (tzname[1] && !strncmp(*s, tzname[1], len=strlen(tzname[1]))) { + isdst = 1; + *s += len; + } else { + /* FIXME: is this supposed to be an error? */ + while (isalpha(**s)) ++*s; + } + UNLOCK(lock); + return isdst; +} diff --git a/src/time/__utc.c b/src/time/__utc.c new file mode 100644 index 00000000..9e8bfc58 --- /dev/null +++ b/src/time/__utc.c @@ -0,0 +1,3 @@ +#include "time_impl.h" + +const char __utc[] = "UTC"; diff --git a/src/time/strptime.c b/src/time/strptime.c index b1147242..40bb37af 100644 --- a/src/time/strptime.c +++ b/src/time/strptime.c @@ -5,6 +5,7 @@ #include <stddef.h> #include <string.h> #include <strings.h> +#include "time_impl.h" char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm) { @@ -207,16 +208,8 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri s += 5; break; case 'Z': - if (!strncmp(s, tzname[0], len = strlen(tzname[0]))) { - tm->tm_isdst = 0; - s += len; - } else if (!strncmp(s, tzname[1], len=strlen(tzname[1]))) { - tm->tm_isdst = 1; - s += len; - } else { - /* FIXME: is this supposed to be an error? */ - while ((*s|32)-'a' <= 'z'-'a') s++; - } + i = __tzname_to_isdst(&s); + if (i>=0) tm->tm_isdst = i; break; case '%': if (*s++ != '%') return 0; diff --git a/src/time/time_impl.h b/src/time/time_impl.h index f26d8005..ffe5050b 100644 --- a/src/time/time_impl.h +++ b/src/time/time_impl.h @@ -5,6 +5,7 @@ hidden int __month_to_secs(int, int); hidden long long __year_to_secs(long long, int *); hidden long long __tm_to_secs(const struct tm *); hidden const char *__tm_to_tzname(const struct tm *); +hidden int __tzname_to_isdst(const char *restrict *); hidden int __secs_to_tm(long long, struct tm *); hidden void __secs_to_zone(long long, int, int *, long *, long *, const char **); hidden const char *__strftime_fmt_1(char (*)[100], size_t *, int, const struct tm *, locale_t, int); diff --git a/src/time/timer_create.c b/src/time/timer_create.c index 9216b3ab..cc6c2236 100644 --- a/src/time/timer_create.c +++ b/src/time/timer_create.c @@ -1,6 +1,7 @@ #include <time.h> #include <setjmp.h> #include <limits.h> +#include <semaphore.h> #include "pthread_impl.h" #include "atomic.h" @@ -12,7 +13,7 @@ struct ksigevent { }; struct start_args { - pthread_barrier_t b; + sem_t sem1, sem2; struct sigevent *sev; }; @@ -21,10 +22,16 @@ static void dummy_0() } weak_alias(dummy_0, __pthread_tsd_run_dtors); +static void timer_handler(int sig, siginfo_t *si, void *ctx) +{ +} + static void cleanup_fromsig(void *p) { pthread_t self = __pthread_self(); __pthread_tsd_run_dtors(); + __block_app_sigs(0); + __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGTIMER_SET, 0, _NSIG/8); self->cancel = 0; self->cancelbuf = 0; self->canceldisable = 0; @@ -42,7 +49,14 @@ static void *start(void *arg) void (*notify)(union sigval) = args->sev->sigev_notify_function; union sigval val = args->sev->sigev_value; - pthread_barrier_wait(&args->b); + /* The two-way semaphore synchronization ensures that we see + * self->cancel set by the parent if timer creation failed or + * self->timer_id if it succeeded, and informs the parent that + * we are done accessing the arguments so that the parent can + * proceed past their block lifetime. */ + while (sem_wait(&args->sem1)); + sem_post(&args->sem2); + if (self->cancel) return 0; for (;;) { @@ -90,7 +104,10 @@ int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict break; case SIGEV_THREAD: if (!init) { - struct sigaction sa = { .sa_handler = SIG_DFL }; + struct sigaction sa = { + .sa_sigaction = timer_handler, + .sa_flags = SA_SIGINFO | SA_RESTART + }; __libc_sigaction(SIGTIMER, &sa, 0); a_store(&init, 1); } @@ -99,7 +116,8 @@ int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict else pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_barrier_init(&args.b, 0, 2); + sem_init(&args.sem1, 0, 0); + sem_init(&args.sem2, 0, 0); args.sev = evp; __block_app_sigs(&set); @@ -120,7 +138,8 @@ int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict td->cancel = 1; } td->timer_id = timerid; - pthread_barrier_wait(&args.b); + sem_post(&args.sem1); + while (sem_wait(&args.sem2)); if (timerid < 0) return -1; *res = (void *)(INTPTR_MIN | (uintptr_t)td>>1); break; |
