apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r529791 - in /apr/apr-util/trunk: include/apr_thread_pool.h misc/apr_thread_pool.c
Date Tue, 17 Apr 2007 22:17:23 GMT
Author: wrowe
Date: Tue Apr 17 15:17:18 2007
New Revision: 529791

URL: http://svn.apache.org/viewvc?view=rev&rev=529791
Log:
Fix the assert, which should only for preventing task from owner itself
calling cancel.

Adds a apr_thread_pool_task_owner_get API to retrieve the owner of the task.
This is convenient and can, in many cases, eliminate the need to create a
structure to use as parameters.

PR: 41359
Submitted by: Henry Jen <henryjen ztune.net>

Modified:
    apr/apr-util/trunk/include/apr_thread_pool.h
    apr/apr-util/trunk/misc/apr_thread_pool.c

Modified: apr/apr-util/trunk/include/apr_thread_pool.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/include/apr_thread_pool.h?view=diff&rev=529791&r1=529790&r2=529791
==============================================================================
--- apr/apr-util/trunk/include/apr_thread_pool.h (original)
+++ apr/apr-util/trunk/include/apr_thread_pool.h Tue Apr 17 15:17:18 2007
@@ -226,6 +226,15 @@
  */
 APR_DECLARE(apr_size_t) apr_thread_pool_threshold_get(apr_thread_pool_t * me);
 
+/**
+ * Get owner of the task currently been executed by the thread. 
+ * @param thd The thread is executing a task 
+ * @param owner Pointer to receive owner of the task.
+ * @return APR_SUCCESS if the owner is retrieved successfully
+ */
+APR_DECLARE(apr_status_t) apr_thread_pool_task_owner_get(apr_thread_t * thd,
+                                                         void **owner);
+
 #ifdef __cplusplus
 #if 0
 {

Modified: apr/apr-util/trunk/misc/apr_thread_pool.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/misc/apr_thread_pool.c?view=diff&rev=529791&r1=529790&r2=529791
==============================================================================
--- apr/apr-util/trunk/misc/apr_thread_pool.c (original)
+++ apr/apr-util/trunk/misc/apr_thread_pool.c Tue Apr 17 15:17:18 2007
@@ -233,6 +233,7 @@
         while (NULL != task && !me->terminated) {
             elt->current_owner = task->owner;
             apr_thread_mutex_unlock(me->lock);
+            apr_thread_data_set(task, "apr_thread_pool_task", NULL, t);
             task->func(t, task->param);
             apr_thread_mutex_lock(me->lock);
             APR_RING_INSERT_TAIL(me->recycled_tasks, task,
@@ -598,6 +599,10 @@
     apr_thread_mutex_lock(me->lock);
     elt = APR_RING_FIRST(me->busy_thds);
     while (elt != APR_RING_SENTINEL(me->busy_thds, apr_thread_list_elt, link)) {
+        if (elt->current_owner != owner) {
+            elt = APR_RING_NEXT(elt, link);
+            continue;
+        }
 #ifndef NDEBUG
         /* make sure the thread is not the one calling tasks_cancel */
         apr_os_thread_t *os_thread;
@@ -609,10 +614,6 @@
         assert(!apr_os_thread_equal(apr_os_thread_current(), *os_thread));
 #endif
 #endif
-        if (elt->current_owner != owner) {
-            elt = APR_RING_NEXT(elt, link);
-            continue;
-        }
         while (elt->current_owner == owner) {
             apr_thread_mutex_unlock(me->lock);
             apr_sleep(200 * 1000);
@@ -810,6 +811,26 @@
     ov = me->threshold;
     me->threshold = val;
     return ov;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_pool_task_owner_get(apr_thread_t * thd,
+                                                         void **owner)
+{
+    apr_status_t rv;
+    apr_thread_pool_task_t * task;
+    
+    rv = apr_thread_data_get((void**) &task, "apr_thread_pool_task", thd);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    if (!task) {
+        *owner = NULL;
+        return APR_BADARG;
+    }
+    
+    *owner = task->owner;
+    return APR_SUCCESS;
 }
 
 #endif /* APR_HAS_THREADS */



Mime
View raw message