semaphores are a much lighter primitive, and more idiomatic with
current usage in the code base.
#include <sys/socket.h>
#include <signal.h>
#include <unistd.h>
#include <sys/socket.h>
#include <signal.h>
#include <unistd.h>
#include "syscall.h"
struct args {
#include "syscall.h"
struct args {
- pthread_barrier_t barrier;
int sock;
const struct sigevent *sev;
};
int sock;
const struct sigevent *sev;
};
void (*func)(union sigval) = args->sev->sigev_notify_function;
union sigval val = args->sev->sigev_value;
void (*func)(union sigval) = args->sev->sigev_notify_function;
union sigval val = args->sev->sigev_value;
- pthread_barrier_wait(&args->barrier);
n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
close(s);
if (n==sizeof buf && buf[sizeof buf - 1] == 1)
n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
close(s);
if (n==sizeof buf && buf[sizeof buf - 1] == 1)
int s;
struct sigevent sev2;
static const char zeros[32];
int s;
struct sigevent sev2;
static const char zeros[32];
if (!sev || sev->sigev_notify != SIGEV_THREAD)
return syscall(SYS_mq_notify, mqd, sev);
if (!sev || sev->sigev_notify != SIGEV_THREAD)
return syscall(SYS_mq_notify, mqd, sev);
if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes;
else pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes;
else pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- pthread_barrier_init(&args.barrier, 0, 2);
+ sem_init(&args.sem, 0, 0);
if (pthread_create(&td, &attr, start, &args)) {
__syscall(SYS_close, s);
if (pthread_create(&td, &attr, start, &args)) {
__syscall(SYS_close, s);
- pthread_barrier_wait(&args.barrier);
- pthread_barrier_destroy(&args.barrier);
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+ sem_wait(&args.sem);
+ pthread_setcancelstate(cs, 0);
+ sem_destroy(&args.sem);
sev2.sigev_notify = SIGEV_THREAD;
sev2.sigev_signo = s;
sev2.sigev_notify = SIGEV_THREAD;
sev2.sigev_signo = s;