1 #include "pthread_impl.h"
9 static void (*callback)(void *), *context;
11 static sem_t chainlock, chaindone;
12 static pthread_rwlock_t lock = PTHREAD_RWLOCK_INITIALIZER;
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 /* Threads which have already decremented themselves from the
25 * thread count must not act. Block further receipt of signals
28 memset(&((ucontext_t *)ctx)->uc_sigmask, -1, 8);
33 sem_init(&ch.sem, 0, 0);
34 sem_init(&ch.sem2, 0, 0);
36 while (sem_wait(&chainlock));
39 if (++chainlen == libc.threads_minus_1) sem_post(&chaindone);
42 while (sem_wait(&ch.sem));
45 while (sem_wait(&ch.sem));
50 void __synccall(void (*func)(void *), void *ctx)
57 if (!libc.threads_minus_1) {
62 pthread_rwlock_wrlock(&lock);
64 __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGALL_SET,
65 &oldmask, __SYSCALL_SSLEN);
67 sem_init(&chaindone, 0, 0);
68 sem_init(&chainlock, 0, 1);
73 sa.sa_flags = SA_SIGINFO | SA_RESTART;
74 sa.sa_sigaction = handler;
75 sigfillset(&sa.sa_mask);
76 __libc_sigaction(SIGSYNCCALL, &sa, 0);
78 self = __pthread_self();
79 sigqueue(self->pid, SIGSYNCCALL, (union sigval){0});
80 while (sem_wait(&chaindone));
82 for (cur=head; cur; cur=cur->next) {
84 while (sem_wait(&cur->sem2));
88 for (cur=head; cur; cur=next) {
94 sa.sa_handler = SIG_IGN;
95 __libc_sigaction(SIGSYNCCALL, &sa, 0);
97 __syscall(SYS_rt_sigprocmask, SIG_SETMASK,
98 &oldmask, 0, __SYSCALL_SSLEN);
100 pthread_rwlock_unlock(&lock);
103 void __synccall_lock()
105 pthread_rwlock_rdlock(&lock);
108 void __synccall_unlock()
110 pthread_rwlock_unlock(&lock);