diff --git a/src/lib/empthread/pthread.c b/src/lib/empthread/pthread.c index 65438a84..d4ede07d 100644 --- a/src/lib/empthread/pthread.c +++ b/src/lib/empthread/pthread.c @@ -88,7 +88,7 @@ static void **udata; static pthread_mutex_t mtx_ctxsw; static void empth_status(char *format, ...) ATTRIBUTE((format (printf, 1, 2))); - +static void empth_alarm(int sig); static void * empth_start(void *arg) @@ -110,6 +110,9 @@ empth_start(void *arg) act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); + act.sa_handler = empth_alarm; + sigaction(SIGALRM, &act, NULL); + ctx->id = pthread_self(); pthread_setspecific(ctx_key, ctx); pthread_mutex_lock(&mtx_ctxsw); @@ -154,11 +157,17 @@ int empth_init(void **ctx_ptr, int flags) { empth_t *ctx; + struct sigaction act; pthread_key_create(&ctx_key, NULL); pthread_mutex_init(&mtx_ctxsw, NULL); + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + act.sa_handler = empth_alarm; + sigaction(SIGALRM, &act, NULL); + udata = ctx_ptr; ctx = malloc(sizeof(empth_t)); if (!ctx) { @@ -354,6 +363,19 @@ empth_select(int fd, int flags) } +static void +empth_alarm(int sig) +{ + struct sigaction act; + empth_status("got alarm signal"); +#ifdef SA_RESTART + act.sa_flags &= ~SA_RESTART; +#endif + sigemptyset(&act.sa_mask); + act.sa_handler = empth_alarm; + sigaction(SIGALRM, &act, NULL); +} + void empth_wakeup(empth_t *a) {