]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Fork if no threading is available.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 27 Feb 2007 09:41:34 +0000 (09:41 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 27 Feb 2007 09:41:34 +0000 (09:41 +0000)
git-svn-id: file:///svn/unbound/trunk@151 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
util/locks.c
util/locks.h
util/netevent.c

index e4728f3a49e569faa7a402bb72e58a72183f4dc3..36f7c0fdca66dc04cfeaa78fa11af16148777bd4 100644 (file)
@@ -1,6 +1,8 @@
 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.
index b6b821ce0fcad6952d4a8906b51e65ee6d4171b3..6df14ead8282bd60079e345829ab7d428327ac4a 100644 (file)
@@ -104,10 +104,10 @@ ub_thr_fork_create(ub_thread_t* thr, void* (*func)(void*), void* arg)
        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 */
@@ -123,7 +123,7 @@ ub_thr_fork_create(ub_thread_t* thr, void* (*func)(void*), void* arg)
 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",
index 240a0898251b53568887269ca59812966fc86beb..fe04aae3bcf510a216e20004fbe601d98d3fe2ff 100644 (file)
@@ -184,13 +184,14 @@ typedef int lock_quick_t;
 
 /** 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 */
index f183be6a786a473b2ca665c80f7591b2a412a603..a51d59217173a2916eba595090730076c795b493 100644 (file)
@@ -173,6 +173,8 @@ comm_base_create()
 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);