1 #include "pthread_impl.h"
9 static void (*callback)(void *), *context;
11 static sem_t chainlock, chaindone;
13 static void handler(int sig, siginfo_t *si, void *ctx)
16 pthread_t self = __pthread_self();
17 int old_errno = errno;
19 if (chainlen == libc.threads_minus_1) return;
21 sigqueue(self->pid, SIGSYNCCALL, (union sigval){0});
23 /* Threads which have already decremented themselves from the
24 * thread count must not act. Block further receipt of signals
27 memset(&((ucontext_t *)ctx)->uc_sigmask, -1, 8);
32 sem_init(&ch.sem, 0, 0);
33 sem_init(&ch.sem2, 0, 0);
35 while (sem_wait(&chainlock));
38 if (++chainlen == libc.threads_minus_1) sem_post(&chaindone);
41 while (sem_wait(&ch.sem));
44 while (sem_wait(&ch.sem));
49 void __synccall(void (*func)(void *), void *ctx)
56 if (!libc.threads_minus_1) {
63 __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGALL_SET,
64 &oldmask, __SYSCALL_SSLEN);
66 sem_init(&chaindone, 0, 0);
67 sem_init(&chainlock, 0, 1);
72 sa.sa_flags = SA_SIGINFO | SA_RESTART;
73 sa.sa_sigaction = handler;
74 sigfillset(&sa.sa_mask);
75 __libc_sigaction(SIGSYNCCALL, &sa, 0);
77 self = __pthread_self();
78 sigqueue(self->pid, SIGSYNCCALL, (union sigval){0});
79 while (sem_wait(&chaindone));
81 for (cur=head; cur; cur=cur->next) {
83 while (sem_wait(&cur->sem2));
87 for (cur=head; cur; cur=next) {
93 sa.sa_handler = SIG_IGN;
94 __libc_sigaction(SIGSYNCCALL, &sa, 0);
96 __syscall(SYS_rt_sigprocmask, SIG_SETMASK,
97 &oldmask, 0, __SYSCALL_SSLEN);