27 February 2007: Wouter
- ub_thread_join portable definition.
- forking is used if no threading is available.
+ Tested, it works, since pipes work across processes as well.
+ Thread_join is replaced with waitpid.
26 February 2007: Wouter
- ub_random code used to select ID and port.
pid_t pid = fork();
switch(pid) {
default: /* main */
- *thr = pid;
+ *thr = (ub_thread_t)pid;
return;
case 0: /* child */
- *thr = getpid();
+ *thr = (ub_thread_t)getpid();
(void)(*func)(arg);
exit(0);
case -1: /* error */
void ub_thr_fork_wait(ub_thread_t thread)
{
int status = 0;
- if(waitpid(thread, &status, 0) == -1)
+ if(waitpid((pid_t)thread, &status, 0) == -1)
log_err("waitpid(%d): %s", (int)thread, strerror(errno));
if(status != 0)
log_warn("process %d abnormal exit with status %d",
/** Thread creation, threads do not exist */
typedef pid_t ub_thread_t;
-/** ub_thread_create gives an error, it should not be called. */
+/** ub_thread_create is simulated with fork (extremely heavy threads,
+ * with no shared memory). */
#define ub_thread_create(thr, func, arg) \
ub_thr_fork_create(thr, func, arg)
- fatal_exit("%s %d called thread create, but no thread support " \
- "has been compiled in.", __FILE__, __LINE__)
#define ub_thread_self() getpid()
#define ub_thread_join(thread) ub_thr_fork_wait(thread)
+void ub_thr_fork_wait(ub_thread_t thread);
+void ub_thr_fork_create(ub_thread_t* thr, void* (*func)(void*), void* arg);
#endif /* HAVE_SOLARIS_THREADS */
#endif /* HAVE_PTHREAD */
void
comm_base_delete(struct comm_base* b)
{
+ if(!b)
+ return;
#ifdef HAVE_EVENT_BASE_FREE
/* only libevent 1.2+ has it */
event_base_free(b->eb->base);