2 * threads.c request threading support
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2000,2006 The FreeRADIUS server project
21 * Copyright 2000 Alan DeKok <aland@ox.org>
24 #include <freeradius-devel/ident.h>
27 #include <freeradius-devel/autoconf.h>
33 * Other OS's have sem_init, OS X doesn't.
36 #include <semaphore.h>
38 #include <mach/task.h>
39 #include <mach/semaphore.h>
42 #define sem_t semaphore_t
44 #define sem_init(s,p,c) semaphore_create(mach_task_self(),s,SYNC_POLICY_FIFO,c)
46 #define sem_wait(s) semaphore_wait(*s)
48 #define sem_post(s) semaphore_signal(*s)
53 #ifdef HAVE_SYS_WAIT_H
57 #include <freeradius-devel/radiusd.h>
58 #include <freeradius-devel/rad_assert.h>
59 #include <freeradius-devel/modules.h>
63 #ifdef HAVE_OPENSSL_CRYPTO_H
64 #include <openssl/crypto.h>
66 #ifdef HAVE_OPENSSL_ERR_H
67 #include <openssl/err.h>
70 #define SEMAPHORE_LOCKED (0)
71 #define SEMAPHORE_UNLOCKED (1)
73 #define THREAD_RUNNING (1)
74 #define THREAD_CANCELLED (2)
75 #define THREAD_EXITED (3)
80 * Ordered this way because we prefer proxy, then ongoing, then
83 #define FIFO_START (1)
84 #define FIFO_PROXY (0)
87 * A data structure which contains the information about
90 * pthread_id pthread id
91 * thread_num server thread number, 1...number of threads
92 * semaphore used to block the thread until a request comes in
93 * status is the thread running or exited?
94 * request_count the number of requests that this thread has handled
95 * timestamp when the thread started executing.
97 typedef struct THREAD_HANDLE {
98 struct THREAD_HANDLE *prev;
99 struct THREAD_HANDLE *next;
100 pthread_t pthread_id;
103 unsigned int request_count;
109 * For the request queue.
111 typedef struct request_queue_t {
113 RAD_REQUEST_FUNP fun;
116 typedef struct thread_fork_t {
124 * A data structure to manage the thread pool. There's no real
125 * need for a data structure, but it makes things conceptually
128 typedef struct THREAD_POOL {
133 int active_threads; /* protected by queue_mutex */
137 int min_spare_threads;
138 int max_spare_threads;
139 unsigned int max_requests_per_thread;
140 unsigned long request_count;
141 time_t time_last_spawned;
145 pthread_mutex_t wait_mutex;
146 lrad_hash_table_t *waiters;
149 * All threads wait on this semaphore, for requests
150 * to enter the queue.
155 * To ensure only one thread at a time touches the queue.
157 pthread_mutex_t queue_mutex;
162 lrad_fifo_t *fifo[NUM_FIFOS];
165 static THREAD_POOL thread_pool;
166 static int pool_initialized = FALSE;
170 * A mapping of configuration file names to internal integers
172 static const CONF_PARSER thread_config[] = {
173 { "start_servers", PW_TYPE_INTEGER, 0, &thread_pool.start_threads, "5" },
174 { "max_servers", PW_TYPE_INTEGER, 0, &thread_pool.max_threads, "32" },
175 { "min_spare_servers", PW_TYPE_INTEGER, 0, &thread_pool.min_spare_threads, "3" },
176 { "max_spare_servers", PW_TYPE_INTEGER, 0, &thread_pool.max_spare_threads, "10" },
177 { "max_requests_per_server", PW_TYPE_INTEGER, 0, &thread_pool.max_requests_per_thread, "0" },
178 { "cleanup_delay", PW_TYPE_INTEGER, 0, &thread_pool.cleanup_delay, "5" },
179 { "max_queue_size", PW_TYPE_INTEGER, 0, &thread_pool.max_queue_size, "65536" },
180 { NULL, -1, 0, NULL, NULL }
184 #ifdef HAVE_OPENSSL_CRYPTO_H
187 * If we're linking against OpenSSL, then it is the
188 * duty of the application, if it is multithreaded,
189 * to provide OpenSSL with appropriate thread id
190 * and mutex locking functions
192 * Note: this only implements static callbacks.
193 * OpenSSL does not use dynamic locking callbacks
194 * right now, but may in the futiure, so we will have
195 * to add them at some point.
198 static pthread_mutex_t *ssl_mutexes = NULL;
200 static unsigned long ssl_id_function(void)
202 return (unsigned long) pthread_self();
205 static void ssl_locking_function(int mode, int n, const char *file, int line)
207 file = file; /* -Wunused */
208 line = line; /* -Wunused */
210 if (mode & CRYPTO_LOCK) {
211 pthread_mutex_lock(&(ssl_mutexes[n]));
213 pthread_mutex_unlock(&(ssl_mutexes[n]));
217 static int setup_ssl_mutexes(void)
221 ssl_mutexes = rad_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
223 radlog(L_ERR, "Error allocating memory for SSL mutexes!");
227 for (i = 0; i < CRYPTO_num_locks(); i++) {
228 pthread_mutex_init(&(ssl_mutexes[i]), NULL);
231 CRYPTO_set_id_callback(ssl_id_function);
232 CRYPTO_set_locking_callback(ssl_locking_function);
240 * We don't want to catch SIGCHLD for a host of reasons.
242 * - exec_wait means that someone, somewhere, somewhen, will
243 * call waitpid(), and catch the child.
245 * - SIGCHLD is delivered to a random thread, not the one that
248 * - if another thread catches the child, we have to coordinate
249 * with the thread doing the waiting.
251 * - if we don't waitpid() for non-wait children, they'll be zombies,
252 * and will hang around forever.
255 static void reap_children(void)
259 thread_fork_t mytf, *tf;
262 pthread_mutex_lock(&thread_pool.wait_mutex);
265 pid = waitpid(0, &status, WNOHANG);
269 tf = lrad_hash_table_finddata(thread_pool.waiters, &mytf);
274 } while (lrad_hash_table_num_elements(thread_pool.waiters) > 0);
276 pthread_mutex_unlock(&thread_pool.wait_mutex);
280 * Add a request to the list of waiting requests.
281 * This function gets called ONLY from the main handler thread...
283 * This function should never fail.
285 static int request_enqueue(REQUEST *request, RAD_REQUEST_FUNP fun)
287 int fifo = FIFO_START;
288 request_queue_t *entry;
290 pthread_mutex_lock(&thread_pool.queue_mutex);
292 thread_pool.request_count++;
295 * FIXME: Handle proxy replies separately?
297 if (thread_pool.num_queued >= thread_pool.max_queue_size) {
298 pthread_mutex_unlock(&thread_pool.queue_mutex);
301 * Mark the request as done.
303 radlog(L_ERR|L_CONS, "!!! ERROR !!! The server is blocked: discarding new request %d", request->number);
304 request->child_state = REQUEST_DONE;
309 * Requests get handled in priority. First, we handle
310 * replies from a home server, to finish ongoing requests.
312 * Then, we handle requests with State, to finish
313 * multi-packet transactions.
315 * Finally, we handle new requests.
317 if (request->proxy_reply) {
323 entry = rad_malloc(sizeof(*entry));
324 entry->request = request;
327 if (!lrad_fifo_push(thread_pool.fifo[fifo], entry)) {
328 pthread_mutex_unlock(&thread_pool.queue_mutex);
329 radlog(L_ERR, "!!! ERROR !!! Failed inserting request %d into the queue", request->number);
330 request->child_state = REQUEST_DONE;
334 thread_pool.num_queued++;
336 pthread_mutex_unlock(&thread_pool.queue_mutex);
339 * There's one more request in the queue.
341 * Note that we're not touching the queue any more, so
342 * the semaphore post is outside of the mutex. This also
343 * means that when the thread wakes up and tries to lock
344 * the mutex, it will be unlocked, and there won't be
347 sem_post(&thread_pool.semaphore);
353 * Remove a request from the queue.
355 static int request_dequeue(REQUEST **request, RAD_REQUEST_FUNP *fun)
358 request_queue_t *entry;
362 pthread_mutex_lock(&thread_pool.queue_mutex);
364 fifo_state = thread_pool.fifo_state;
369 * Pop an entry from the current queue, and go to
372 entry = lrad_fifo_pop(thread_pool.fifo[fifo_state]);
374 if (fifo_state >= NUM_FIFOS) fifo_state = 0;
375 } while ((fifo_state != thread_pool.fifo_state) && !entry);
378 pthread_mutex_unlock(&thread_pool.queue_mutex);
384 rad_assert(thread_pool.num_queued > 0);
385 thread_pool.num_queued--;
386 *request = entry->request;
390 rad_assert(*request != NULL);
391 rad_assert((*request)->magic == REQUEST_MAGIC);
392 rad_assert(*fun != NULL);
395 * If the request has sat in the queue for too long,
398 * The main clean-up code won't delete the request from
399 * the request list, until it's marked "finished"
401 if ((*request)->master_state == REQUEST_STOP_PROCESSING) {
402 (*request)->child_state = REQUEST_DONE;
407 * The thread is currently processing a request.
409 thread_pool.active_threads++;
410 thread_pool.fifo_state = fifo_state;
412 pthread_mutex_unlock(&thread_pool.queue_mutex);
414 rad_assert((*request)->child_pid == NO_SUCH_CHILD_PID);
421 * The main thread handler for requests.
423 * Wait on the semaphore until we have it, and process the request.
425 static void *request_handler_thread(void *arg)
427 RAD_REQUEST_FUNP fun;
428 THREAD_HANDLE *self = (THREAD_HANDLE *) arg;
429 #ifdef HAVE_PTHREAD_SIGMASK
433 * Block SIGHUP handling for the child threads.
435 * This ensures that only the main server thread will
436 * process HUP signals.
438 * If we don't have sigprocmask, then it shouldn't be
439 * a problem, either, as the sig_hup handler should check
440 * for this condition.
443 sigaddset(&set, SIGHUP);
444 sigaddset(&set, SIGINT);
445 sigaddset(&set, SIGQUIT);
446 sigaddset(&set, SIGTERM);
447 pthread_sigmask(SIG_BLOCK, &set, NULL);
451 * Loop forever, until told to exit.
455 * Wait to be signalled.
457 DEBUG2("Thread %d waiting to be assigned a request",
460 if (sem_wait(&thread_pool.semaphore) != 0) {
462 * Interrupted system call. Go back to
463 * waiting, but DON'T print out any more
466 if (errno == EINTR) {
467 DEBUG2("Re-wait %d", self->thread_num);
470 radlog(L_ERR, "Thread %d failed waiting for semaphore: %s: Exiting\n",
471 self->thread_num, strerror(errno));
475 DEBUG2("Thread %d got semaphore", self->thread_num);
478 * Try to grab a request from the queue.
480 * It may be empty, in which case we fail
483 if (!request_dequeue(&self->request, &fun)) continue;
485 self->request->child_pid = self->pthread_id;
486 self->request_count++;
488 DEBUG2("Thread %d handling request %d, (%d handled so far)",
489 self->thread_num, self->request->number,
490 self->request_count);
492 radius_handle_request(self->request, fun);
495 * Update the active threads.
497 pthread_mutex_lock(&thread_pool.queue_mutex);
498 rad_assert(thread_pool.active_threads > 0);
499 thread_pool.active_threads--;
500 pthread_mutex_unlock(&thread_pool.queue_mutex);
501 } while (self->status != THREAD_CANCELLED);
503 DEBUG2("Thread %d exiting...", self->thread_num);
505 #ifdef HAVE_OPENSSL_ERR_H
507 * If we linked with OpenSSL, the application
508 * must remove the thread's error queue before
509 * exiting to prevent memory leaks.
515 * Do this as the LAST thing before exiting.
517 self->status = THREAD_EXITED;
523 * Take a THREAD_HANDLE, delete it from the thread pool and
524 * free its resources.
526 * This function is called ONLY from the main server thread,
527 * ONLY after the thread has exited.
529 static void delete_thread(THREAD_HANDLE *handle)
534 rad_assert(handle->request == NULL);
536 DEBUG2("Deleting thread %d", handle->thread_num);
540 rad_assert(thread_pool.total_threads > 0);
541 thread_pool.total_threads--;
544 * Remove the handle from the list.
547 rad_assert(thread_pool.head == handle);
548 thread_pool.head = next;
554 rad_assert(thread_pool.tail == handle);
555 thread_pool.tail = prev;
561 * Free the handle, now that it's no longer referencable.
568 * Spawn a new thread, and place it in the thread pool.
570 * The thread is started initially in the blocked state, waiting
573 static THREAD_HANDLE *spawn_thread(time_t now)
576 THREAD_HANDLE *handle;
580 * Ensure that we don't spawn too many threads.
582 if (thread_pool.total_threads >= thread_pool.max_threads) {
583 DEBUG2("Thread spawn failed. Maximum number of threads (%d) already running.", thread_pool.max_threads);
588 * Allocate a new thread handle.
590 handle = (THREAD_HANDLE *) rad_malloc(sizeof(THREAD_HANDLE));
591 memset(handle, 0, sizeof(THREAD_HANDLE));
594 handle->pthread_id = NO_SUCH_CHILD_PID;
595 handle->thread_num = thread_pool.max_thread_num++;
596 handle->request_count = 0;
597 handle->status = THREAD_RUNNING;
598 handle->timestamp = time(NULL);
601 * Initialize the thread's attributes to detached.
603 * We could call pthread_detach() later, but if the thread
604 * exits between the create & detach calls, it will need to
605 * be joined, which will never happen.
607 pthread_attr_init(&attr);
608 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
611 * Create the thread detached, so that it cleans up it's
612 * own memory when it exits.
614 * Note that the function returns non-zero on error, NOT
615 * -1. The return code is the error, and errno isn't set.
617 rcode = pthread_create(&handle->pthread_id, &attr,
618 request_handler_thread, handle);
620 radlog(L_ERR|L_CONS, "FATAL: Thread create failed: %s",
624 pthread_attr_destroy(&attr);
627 * One more thread to go into the list.
629 thread_pool.total_threads++;
630 DEBUG2("Thread spawned new child %d. Total threads in pool: %d",
631 handle->thread_num, thread_pool.total_threads);
634 * Add the thread handle to the tail of the thread pool list.
636 if (thread_pool.tail) {
637 thread_pool.tail->next = handle;
638 handle->prev = thread_pool.tail;
639 thread_pool.tail = handle;
641 rad_assert(thread_pool.head == NULL);
642 thread_pool.head = thread_pool.tail = handle;
646 * Update the time we last spawned a thread.
648 thread_pool.time_last_spawned = now;
651 * And return the new handle to the caller.
657 * Temporary function to prevent server from executing a SIGHUP
658 * until all threads are finished handling requests. This returns
659 * the number of active threads to 'radiusd.c'.
661 int total_active_threads(void)
664 * We don't acquire the mutex, so this is just an estimate.
665 * We can't return with the lock held, so there's no point
666 * in getting the guaranteed correct value; by the time
667 * the caller sees it, it can be wrong again.
669 return thread_pool.active_threads;
673 static uint32_t pid_hash(const void *data)
675 const thread_fork_t *tf = data;
677 return lrad_hash(&tf->pid, sizeof(tf->pid));
680 static int pid_cmp(const void *one, const void *two)
682 const thread_fork_t *a = one;
683 const thread_fork_t *b = two;
685 return (a->pid - b->pid);
689 * Allocate the thread pool, and seed it with an initial number
692 * FIXME: What to do on a SIGHUP???
694 int thread_pool_init(int spawn_flag)
697 CONF_SECTION *pool_cf;
700 DEBUG("Initializing the thread pool...");
704 * We're not spawning new threads, don't do
707 if (!spawn_flag) return 0;
710 * After a SIGHUP, we don't over-write the previous values.
712 if (!pool_initialized) {
714 * Initialize the thread pool to some reasonable values.
716 memset(&thread_pool, 0, sizeof(THREAD_POOL));
717 thread_pool.head = NULL;
718 thread_pool.tail = NULL;
719 thread_pool.total_threads = 0;
720 thread_pool.max_thread_num = 1;
721 thread_pool.cleanup_delay = 5;
722 thread_pool.spawn_flag = spawn_flag;
724 if ((pthread_mutex_init(&thread_pool.wait_mutex,NULL) != 0)) {
725 radlog(L_ERR, "FATAL: Failed to initialize wait mutex: %s",
731 * Create the hash table of child PID's
733 thread_pool.waiters = lrad_hash_table_create(pid_hash,
736 if (!thread_pool.waiters) {
737 radlog(L_ERR, "FATAL: Failed to set up wait hash");
742 pool_cf = cf_section_find("thread");
743 if (pool_cf != NULL) {
745 * FIXME: Check for errors?
747 cf_section_parse(pool_cf, NULL, thread_config);
751 * The pool has already been initialized. Don't spawn
752 * new threads, and don't forget about forked children,
754 if (pool_initialized) {
759 * Initialize the queue of requests.
761 memset(&thread_pool.semaphore, 0, sizeof(thread_pool.semaphore));
762 rcode = sem_init(&thread_pool.semaphore, 0, SEMAPHORE_LOCKED);
764 radlog(L_ERR|L_CONS, "FATAL: Failed to initialize semaphore: %s",
769 rcode = pthread_mutex_init(&thread_pool.queue_mutex,NULL);
771 radlog(L_ERR, "FATAL: Failed to initialize queue mutex: %s",
777 * Allocate multiple fifos.
779 for (i = 0; i < NUM_FIFOS; i++) {
780 thread_pool.fifo[i] = lrad_fifo_create(65536, NULL);
781 if (!thread_pool.fifo[i]) {
782 radlog(L_ERR, "FATAL: Failed to set up request fifo");
787 #ifdef HAVE_OPENSSL_CRYPTO_H
789 * If we're linking with OpenSSL too, then we need
790 * to set up the mutexes and enable the thread callbacks.
792 if (!setup_ssl_mutexes()) {
793 radlog(L_ERR, "FATAL: Failed to set up SSL mutexes");
800 * Create a number of waiting threads.
802 * If we fail while creating them, do something intelligent.
804 for (i = 0; i < thread_pool.start_threads; i++) {
805 if (spawn_thread(now) == NULL) {
810 DEBUG2("Thread pool initialized");
811 pool_initialized = TRUE;
817 * Assign a new request to a free thread.
819 * If there isn't a free thread, then try to create a new one,
820 * up to the configured limits.
822 int thread_pool_addrequest(REQUEST *request, RAD_REQUEST_FUNP fun)
825 * We've been told not to spawn threads, so don't.
827 if (!thread_pool.spawn_flag) {
828 radius_handle_request(request, fun);
831 * Requests that care about child process exit
832 * codes have already either called
833 * rad_waitpid(), or they've given up.
840 * Add the new request to the queue.
842 if (!request_enqueue(request, fun)) return 0;
845 * If the thread pool is busy handling requests, then
846 * try to spawn another one. We don't acquire the mutex
847 * before reading active_threads, so our thread count is
848 * just an estimate. It's fine to go ahead and spawn an
849 * extra thread in that case.
850 * NOTE: the log message may be in error since active_threads
851 * is an estimate, but it's only in error about the thread
852 * count, not about the fact that we can't create a new one.
854 if (thread_pool.active_threads == thread_pool.total_threads) {
855 if (spawn_thread(request->timestamp) == NULL) {
857 "The maximum number of threads (%d) are active, cannot spawn new thread to handle request",
858 thread_pool.max_threads);
867 * Check the min_spare_threads and max_spare_threads.
869 * If there are too many or too few threads waiting, then we
870 * either create some more, or delete some.
872 int thread_pool_clean(time_t now)
876 THREAD_HANDLE *handle, *next;
878 static time_t last_cleaned = 0;
881 * Loop over the thread pool deleting exited threads.
883 for (handle = thread_pool.head; handle; handle = next) {
887 * Maybe we've asked the thread to exit, and it
890 if (handle->status == THREAD_EXITED) {
891 delete_thread(handle);
896 * We don't need a mutex lock here, as we're reading
897 * active_threads, and not modifying it. We want a close
898 * approximation of the number of active threads, and this
901 active_threads = thread_pool.active_threads;
902 spare = thread_pool.total_threads - active_threads;
904 static int old_total = -1;
905 static int old_active = -1;
907 if ((old_total != thread_pool.total_threads) ||
908 (old_active != active_threads)) {
909 DEBUG2("Threads: total/active/spare threads = %d/%d/%d",
910 thread_pool.total_threads, active_threads, spare);
911 old_total = thread_pool.total_threads;
912 old_active = active_threads;
917 * If there are too few spare threads, create some more.
919 if (spare < thread_pool.min_spare_threads) {
920 total = thread_pool.min_spare_threads - spare;
922 DEBUG2("Threads: Spawning %d spares", total);
924 * Create a number of spare threads.
926 for (i = 0; i < total; i++) {
927 handle = spawn_thread(now);
928 if (handle == NULL) {
934 * And exit, as there can't be too many spare threads.
940 * Only delete spare threads if we haven't already done
943 if (now == last_cleaned) {
949 * Only delete the spare threads if sufficient time has
950 * passed since we last created one. This helps to minimize
951 * the amount of create/delete cycles.
953 if ((now - thread_pool.time_last_spawned) < thread_pool.cleanup_delay) {
958 * If there are too many spare threads, delete one.
960 * Note that we only delete ONE at a time, instead of
961 * wiping out many. This allows the excess servers to
962 * be slowly reaped, just in case the load spike comes again.
964 if (spare > thread_pool.max_spare_threads) {
966 spare -= thread_pool.max_spare_threads;
968 DEBUG2("Threads: deleting 1 spare out of %d spares", spare);
971 * Walk through the thread pool, deleting the
972 * first idle thread we come across.
974 for (handle = thread_pool.head; (handle != NULL) && (spare > 0) ; handle = next) {
978 * If the thread is not handling a
979 * request, but still live, then tell it
982 * It will eventually wake up, and realize
983 * it's been told to commit suicide.
985 if ((handle->request == NULL) &&
986 (handle->status == THREAD_RUNNING)) {
987 handle->status = THREAD_CANCELLED;
989 * Post an extra semaphore, as a
990 * signal to wake up, and exit.
992 sem_post(&thread_pool.semaphore);
1000 * If the thread has handled too many requests, then make it
1003 if (thread_pool.max_requests_per_thread > 0) {
1004 for (handle = thread_pool.head; handle; handle = next) {
1005 next = handle->next;
1008 * Not handling a request, but otherwise
1009 * live, we can kill it.
1011 if ((handle->request == NULL) &&
1012 (handle->status == THREAD_RUNNING) &&
1013 (handle->request_count > thread_pool.max_requests_per_thread)) {
1014 handle->status = THREAD_CANCELLED;
1015 sem_post(&thread_pool.semaphore);
1021 * Otherwise everything's kosher. There are not too few,
1022 * or too many spare threads. Exit happily.
1029 * Thread wrapper for fork().
1031 pid_t rad_fork(void)
1035 if (!pool_initialized) return fork();
1037 reap_children(); /* be nice to non-wait thingies */
1039 if (lrad_hash_table_num_elements(thread_pool.waiters) >= 1024) {
1044 * Fork & save the PID for later reaping.
1047 if (child_pid > 0) {
1051 tf = rad_malloc(sizeof(*tf));
1052 memset(tf, 0, sizeof(*tf));
1054 tf->pid = child_pid;
1056 pthread_mutex_lock(&thread_pool.wait_mutex);
1057 rcode = lrad_hash_table_insert(thread_pool.waiters, tf);
1058 pthread_mutex_unlock(&thread_pool.wait_mutex);
1061 radlog(L_ERR, "Failed to store PID, creating what will be a zombie process %d",
1067 * Return whatever we were told.
1074 * Wait 10 seconds at most for a child to exit, then give up.
1076 pid_t rad_waitpid(pid_t pid, int *status)
1079 thread_fork_t mytf, *tf;
1081 if (!pool_initialized) return waitpid(pid, status, 0);
1083 if (pid <= 0) return -1;
1087 pthread_mutex_lock(&thread_pool.wait_mutex);
1088 tf = lrad_hash_table_finddata(thread_pool.waiters, &mytf);
1089 pthread_mutex_unlock(&thread_pool.wait_mutex);
1093 for (i = 0; i < 100; i++) {
1097 *status = tf->status;
1099 pthread_mutex_lock(&thread_pool.wait_mutex);
1100 lrad_hash_table_delete(thread_pool.waiters, &mytf);
1101 pthread_mutex_unlock(&thread_pool.wait_mutex);
1104 usleep(100000); /* sleep for 1/10 of a second */
1108 * 10 seconds have passed, give up on the child.
1110 pthread_mutex_lock(&thread_pool.wait_mutex);
1111 lrad_hash_table_delete(thread_pool.waiters, &mytf);
1112 pthread_mutex_unlock(&thread_pool.wait_mutex);
1117 #else /* HAVE_PTHREAD_H */
1119 * "thread" code when we don't have threads.
1121 int thread_pool_init(int spawn_flag)
1127 * call "radrespond".
1129 int thread_pool_addrequest(REQUEST *request, RAD_REQUEST_FUNP fun)
1131 rad_respond(request, fun);
1135 #endif /* HAVE_PTHREAD_H */