1 #include "pthread_impl.h"
10 static void (*callback)(void *), *context;
12 static sem_t chainlock, chaindone;
14 static void handler(int sig, siginfo_t *si, void *ctx)
17 pthread_t self = __pthread_self();
18 int old_errno = errno;
20 if (chainlen == libc.threads_minus_1) return;
22 sigqueue(self->pid, SIGSYNCCALL, (union sigval){0});
24 sem_init(&ch.sem, 0, 0);
25 sem_init(&ch.sem2, 0, 0);
27 while (sem_wait(&chainlock));
30 if (++chainlen == libc.threads_minus_1) sem_post(&chaindone);
33 while (sem_wait(&ch.sem));
36 while (sem_wait(&ch.sem));
41 void __synccall(void (*func)(void *), void *ctx)
48 if (!libc.threads_minus_1) {
55 __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGALL_SET,
58 sem_init(&chaindone, 0, 0);
59 sem_init(&chainlock, 0, 1);
65 sa.sa_flags = SA_SIGINFO | SA_RESTART;
66 sa.sa_sigaction = handler;
67 sigfillset(&sa.sa_mask);
68 __libc_sigaction(SIGSYNCCALL, &sa, 0);
70 self = __pthread_self();
71 sigqueue(self->pid, SIGSYNCCALL, (union sigval){0});
72 while (sem_wait(&chaindone));
75 sa.sa_handler = SIG_IGN;
76 __libc_sigaction(SIGSYNCCALL, &sa, 0);
78 for (cur=head; cur; cur=cur->next) {
80 while (sem_wait(&cur->sem2));
84 for (cur=head; cur; cur=next) {
89 __syscall(SYS_rt_sigprocmask, SIG_SETMASK,
90 &oldmask, 0, _NSIG/8);