Clean up threads, and add thread pool lock/unlock functions,
authoraland <aland>
Tue, 9 Oct 2007 15:00:40 +0000 (15:00 +0000)
committeraland <aland>
Tue, 9 Oct 2007 15:00:40 +0000 (15:00 +0000)
in preparation for HUP

src/include/radiusd.h
src/main/radiusd.c
src/main/threads.c

index 1929ff2..8022c1f 100644 (file)
@@ -444,6 +444,8 @@ extern              int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
 extern         pid_t rad_fork(void);
 extern         pid_t rad_waitpid(pid_t pid, int *status);
 extern          int total_active_threads(void);
+extern          void thread_pool_lock(void);
+extern          void thread_pool_unlock(void);
 
 #ifndef HAVE_PTHREAD_H
 #define rad_fork(n) fork()
index 11948b6..1ca2f5b 100644 (file)
@@ -53,6 +53,11 @@ RCSID("$Id$")
 #      define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
 #endif
 
+#ifndef HAVE_PTHREAD_H
+#define thread_pool_lock(_x)
+#define thread_pool_unlock(_x)
+#endif
+
 /*
  *  Global variables.
  */
@@ -415,12 +420,16 @@ int main(int argc, char *argv[])
        }
 
        /*
-        *      Loop while doing stuff.
+        *      Process requests until HUP or exit.
         */
        while ((rcode = radius_event_process()) == 0x80) {
+               thread_pool_lock();
                /*
-                *      HUP handler.
+                *      Reload anything that can safely be reloaded.
                 */
+               DEBUG("HUP support not available.");
+
+               thread_pool_unlock();
        }
        
        DEBUG("Exiting...");
@@ -537,7 +546,5 @@ static void sig_hup(int sig)
 
        reset_signal(SIGHUP, sig_hup);
 
-       write(STDOUT_FILENO, "STUFF\n", 6);
-
        radius_signal_self(RADIUS_SIGNAL_SELF_HUP);
 }
index a05ce2e..d814c3e 100644 (file)
@@ -1123,22 +1123,13 @@ pid_t rad_waitpid(pid_t pid, int *status)
        return 0;
 }
 
-#else /* HAVE_PTHREAD_H */
-/*
- *     "thread" code when we don't have threads.
- */
-int thread_pool_init(int spawn_flag)
+void thread_pool_lock(void)
 {
-       return 0;
+       pthread_mutex_lock(&thread_pool.queue_mutex);
 }
 
-/*
- *     call "radrespond".
- */
-int thread_pool_addrequest(REQUEST *request, RAD_REQUEST_FUNP fun)
+void thread_pool_unlock(void)
 {
-       radius_handle_request(request, fun);
-       return 1;
+       pthread_mutex_unlock(&thread_pool.queue_mutex);
 }
-
 #endif /* HAVE_PTHREAD_H */