fr_schedule_network_t *sn; //!< pointer to the (one) network thread
};
-typedef struct {
- void *(*func)(void *);
- void *arg;
-} fr_schedule_entry_point_t;
-
static _Thread_local int worker_id; //!< Internal ID of the current worker thread.
/** Return the worker id for the current thread
return NULL;
}
-/** Wrapper to set the signal mask on newly created threads
- *
- */
-static void *schedule_pthread_entry(void *arg)
-{
- fr_schedule_entry_point_t *ep = arg;
- sigset_t sig_mask; /* signals to block */
- void *ret;
-
- /*
- * We generally use kqueue to signal threads so we
- * need to mask all the signals to prevent them from
- * being delivered to something that shouldn't be
- * processing them.
- */
- sigfillset(&sig_mask);
-
- if (pthread_sigmask(SIG_BLOCK, &sig_mask, NULL) != 0) {
- free(arg); /* Free memory our parent allocated */
- return NULL;
- }
-
- ret = ep->func(ep->arg);
- free(arg); /* Free memory our parent allocated */
-
- return ret;
-}
-
/** Creates a new thread using our standard set of options
*
* New threads are:
{
pthread_attr_t attr;
int ret;
- fr_schedule_entry_point_t *ep;
/*
* Set the thread to wait around after it's exited
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
- ep = malloc(sizeof(fr_schedule_entry_point_t)); /* MUST be malloc - would corrupt NULL ctx */
- ep->func = func;
- ep->arg = arg;
-
- ret = pthread_create(thread, &attr, schedule_pthread_entry, ep);
+ ret = pthread_create(thread, &attr, func, arg);
if (ret != 0) {
- free(ep);
fr_strerror_printf("Failed creating thread: %s", fr_syserror(ret));
return -1;
}