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 int old_errno = errno;
19 if (chainlen == libc.threads_minus_1) return;
21 sigqueue(getpid(), SIGSYNCCALL, (union sigval){0});
23 sem_init(&ch.sem, 0, 0);
24 sem_init(&ch.sem2, 0, 0);
26 while (sem_wait(&chainlock));
29 if (++chainlen == libc.threads_minus_1) sem_post(&chaindone);
32 while (sem_wait(&ch.sem));
35 while (sem_wait(&ch.sem));
40 void __synccall(void (*func)(void *), void *ctx)
46 if (!libc.threads_minus_1) {
53 __block_all_sigs(&oldmask);
55 sem_init(&chaindone, 0, 0);
56 sem_init(&chainlock, 0, 1);
62 sa.sa_flags = SA_SIGINFO | SA_RESTART;
63 sa.sa_sigaction = handler;
64 sigfillset(&sa.sa_mask);
65 __libc_sigaction(SIGSYNCCALL, &sa, 0);
67 sigqueue(getpid(), SIGSYNCCALL, (union sigval){0});
68 while (sem_wait(&chaindone));
71 sa.sa_handler = SIG_IGN;
72 __libc_sigaction(SIGSYNCCALL, &sa, 0);
74 for (cur=head; cur; cur=cur->next) {
76 while (sem_wait(&cur->sem2));
80 for (cur=head; cur; cur=next) {
85 __restore_sigs(&oldmask);