From 561452f39e2608bc5cb1a8bc3bfeba18ce69ab64 Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Thu, 26 Feb 2015 16:54:26 -0500
Subject: [PATCH] Ticket 48045 - get rid of thread_stack code

Description:  Remove all the thread stack locks/cv.  Keep the stack so we can
              join all the worker threads when we shutdown.

https://fedorahosted.org/389/ticket/48045

Reviewed by: ?

valgrind: PASSED
---
 ns_thrpool.c | 60 ------------------------------------------------------------
 ns_thrpool.h | 20 --------------------
 2 files changed, 80 deletions(-)

diff --git a/ns_thrpool.c b/ns_thrpool.c
index 9101d62..bac483c 100644
--- a/ns_thrpool.c
+++ b/ns_thrpool.c
@@ -15,8 +15,6 @@ struct ns_thrpool_t {
     PRInt32 idle_threads;
     PRUint32 stacksize;
     struct stack_state *thread_stack; /* stack of ns_thread_t */
-    PRLock *thread_stack_lock; /* to support ns_thread_acquire/release */
-    PRCondVar *thread_stack_cv; /* to support ns_thread_acquire/release */
     PRInt32 current_threads;
     PRThread *event_thread; /* the event loop thread */
     struct queue_state *work_q; /* queue of jobs to be executed by the thread pool */
@@ -101,22 +99,6 @@ os_free(void *ptr)
 }
 
 static void
-thread_stack_wait(ns_thrpool_t *tp)
-{
-    PR_Lock(tp->thread_stack_lock);
-    PR_WaitCondVar(tp->thread_stack_cv, PR_INTERVAL_NO_TIMEOUT);
-    PR_Unlock(tp->thread_stack_lock);
-}
-
-static void
-thread_stack_notify(ns_thread_t *thr)
-{
-    PR_Lock(thr->tp->thread_stack_lock);
-    PR_NotifyCondVar(thr->tp->thread_stack_cv);
-    PR_Unlock(thr->tp->thread_stack_lock);
-}
-
-static void
 work_q_wait(ns_thrpool_t *tp)
 {
     PR_Lock(tp->work_q_lock);
@@ -825,12 +807,6 @@ ns_thrpool_new(struct ns_thrpool_config *tp_config)
 
     setup_event_q_wakeup(tp);
 
-    if (!(tp->thread_stack_lock = PR_NewLock())) {
-        goto failed;
-    }
-    if (!(tp->thread_stack_cv = PR_NewCondVar(tp->thread_stack_lock))) {
-        goto failed;
-    }
     for (ii = 0; ii < tp_config->initial_threads; ++ii) {
         thr = PR_NEW(ns_thread_t);
         PR_ASSERT(thr);
@@ -920,18 +896,6 @@ ns_thrpool_destroy(struct ns_thrpool_t *tp)
             tp->work_q_cv = NULL;
         }
 
-        /* Free the thread stack lock. */
-        if (tp->thread_stack_lock) {
-            PR_DestroyLock(tp->thread_stack_lock);
-            tp->thread_stack_lock = NULL;
-        }
-
-        /* Free the thread stack condition variable. */
-        if (tp->thread_stack_cv) {
-            PR_DestroyCondVar(tp->thread_stack_cv);
-            tp->thread_stack_cv = NULL;
-        }
-
         /* Free the event queue. */
         if (tp->event_q) {
             struct ns_job_t *job = NULL;
@@ -1019,30 +983,6 @@ ns_thrpool_wait(ns_thrpool_t *tp)
     return retval;
 }
 
-struct ns_thread_t *
-ns_thread_acquire(struct ns_thrpool_t *tp, PRBool block)
-{
-    /* get a thread from the active queue */
-    struct ns_thread_t *thr = NULL;
-
-    if (ATOMIC_VAL_IS_ZERO(&tp->shutdown)) {
-        while (!stack_pop(tp->thread_stack, (void **)&thr) &&
-               ATOMIC_VAL_IS_ZERO(&tp->shutdown)) {
-            if (block) {
-                thread_stack_wait(tp);
-            }
-        }
-    }
-    return thr;
-}
-
-void
-ns_thread_release(struct ns_thread_t *thr)
-{
-    stack_push(thr->tp->thread_stack, thr);
-    thread_stack_notify(thr);
-}
-
 /*
  * nunc stans logger
  */
diff --git a/ns_thrpool.h b/ns_thrpool.h
index 80dc988..90dd90a 100644
--- a/ns_thrpool.h
+++ b/ns_thrpool.h
@@ -366,26 +366,6 @@ PRInt32 ns_thrpool_is_shutdown(struct ns_thrpool_t *tp);
  */
 PRStatus ns_thrpool_wait(struct ns_thrpool_t *tp);
 
-/**
- * Get a worker thread from the threadpool for the private use of the caller.
- * This is useful when the caller must be able to process incoming
- * requests in the order received.  Since only one thread operates on the
- * job queue, the jobs are guaranteed to be processed in the order added.
- *
- * \param tp The thread pool from which you want to acquire a free thread
- * \param block If true, wait until there is a free thread - if false, do not wait
- * \return \c a thread object
- * \return \c NULL - if block is true, only return NULL if shutting down - if block
- *                   is false, return NULL if no free threads are available
- */
-ns_thread_t *ns_thread_acquire(ns_thrpool_t *tp, PRBool block);
-
-/**
- * Release the worker thread back to the threadpool.
- *
- * \param thr The thread to put back into the free thread list
- */
-void ns_thread_release(ns_thread_t *thr);
 
 /*
  * This is a convenience function - use if you need to re-arm the same event -
-- 
1.9.3

