apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Bannert <aa...@ebuilt.com>
Subject [PATCH] New APR thread API as discussed on list
Date Tue, 24 Jul 2001 00:28:14 GMT
Ok here goes again, hopefully third try's a charm.


This patch updates the APR thread API as discussed on the list
over the last week or so. Basicly, the following changes were made
and are included in this patch:

- worker_function prototype (apr_thread_start_t) now takes two parameters,
  the apr private data (apr_thread_t*) and the application private
  data (void*).

- Applications' worker_thread() routines may now use the apr_thread_pool_get
  routines to access the pool. These are implemented using the
  APR_POOL_*_ACCESSOR() macros.


This patch was tested on UNIX. For the sake of the reviewer, I will followup
this messages with patches that update testthread.c and another that
will implement the changes for httpd. Also, once this gets commited,
I have a fix for apr_thread_join() that needs to get commited. :)

-aaron



Index: include/apr_thread_proc.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_thread_proc.h,v
retrieving revision 1.65
diff -u -r1.65 apr_thread_proc.h
--- include/apr_thread_proc.h	2001/06/06 18:11:06	1.65
+++ include/apr_thread_proc.h	2001/07/24 00:11:19
@@ -125,7 +125,10 @@
 typedef struct apr_other_child_rec_t  apr_other_child_rec_t;
 #endif /* APR_HAS_OTHER_CHILD */
 
-typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(void *);
+/**
+ * The prototype for any APR thread worker functions.
+ */
+typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_t*, void*);
 
 enum kill_conditions {
     kill_never,                 /* process is never sent any signals */
@@ -599,6 +602,14 @@
  * apr_status_t apr_signal_thread((int)(*signal_handler)(int signum))
  */
 APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum));
+
+/**
+ * Get the child-pool used by the thread from the thread info.
+ * @return apr_pool_t the pool
+ * @deffunc apr_pool_t apr_thread_info_pool_get(apr_thread_info_t *i)
+ */
+APR_POOL_DECLARE_ACCESSOR(thread);
+
 #endif /* APR_HAS_THREADS */
 
 #ifdef __cplusplus
Index: include/arch/beos/threadproc.h
===================================================================
RCS file: /home/cvspublic/apr/include/arch/beos/threadproc.h,v
retrieving revision 1.17
diff -u -r1.17 threadproc.h
--- include/arch/beos/threadproc.h	2001/02/16 04:15:49	1.17
+++ include/arch/beos/threadproc.h	2001/07/24 00:11:19
@@ -80,6 +80,8 @@
 struct apr_thread_t {
     apr_pool_t *cntxt;
     thread_id td;
+    void *data;
+    apr_thread_start_t func;
 };
 
 struct apr_threadattr_t {
Index: include/arch/os2/threadproc.h
===================================================================
RCS file: /home/cvspublic/apr/include/arch/os2/threadproc.h,v
retrieving revision 1.9
diff -u -r1.9 threadproc.h
--- include/arch/os2/threadproc.h	2001/02/16 04:15:50	1.9
+++ include/arch/os2/threadproc.h	2001/07/24 00:11:19
@@ -95,7 +95,5 @@
     apr_int32_t detached;
 };
 
-typedef void (*os2_thread_start_t)(void *);
-
 #endif  /* ! THREAD_PROC_H */
 
Index: include/arch/unix/threadproc.h
===================================================================
RCS file: /home/cvspublic/apr/include/arch/unix/threadproc.h,v
retrieving revision 1.18
diff -u -r1.18 threadproc.h
--- include/arch/unix/threadproc.h	2001/04/11 02:01:18	1.18
+++ include/arch/unix/threadproc.h	2001/07/24 00:11:19
@@ -90,6 +90,8 @@
 struct apr_thread_t {
     apr_pool_t *cntxt;
     pthread_t *td;
+    void *data;
+    apr_thread_start_t func;
 };
 
 struct apr_threadattr_t {
Index: include/arch/win32/threadproc.h
===================================================================
RCS file: /home/cvspublic/apr/include/arch/win32/threadproc.h,v
retrieving revision 1.13
diff -u -r1.13 threadproc.h
--- include/arch/win32/threadproc.h	2001/02/16 04:15:52	1.13
+++ include/arch/win32/threadproc.h	2001/07/24 00:11:19
@@ -66,6 +66,8 @@
     HANDLE td;
     apr_int32_t cancel;
     apr_int32_t cancel_how;
+    void *data;
+    apr_thread_start_t func;
 };
 
 struct apr_threadattr_t {
Index: threadproc/beos/thread.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/beos/thread.c,v
retrieving revision 1.22
diff -u -r1.22 thread.c
--- threadproc/beos/thread.c	2001/06/14 18:52:05	1.22
+++ threadproc/beos/thread.c	2001/07/24 00:11:19
@@ -88,6 +88,12 @@
 	return APR_NOTDETACH;
 }
 
+void *dummy_worker(void *opaque)
+{
+    apr_thread_t *thd = (apr_thread_t*)opaque;
+    return thd->func(thd, thd->data);
+}
+
 apr_status_t apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr,
                              apr_thread_start_t func, void *data,
                              apr_pool_t *cont)
@@ -101,6 +107,8 @@
     }
 
     (*new)->cntxt = cont;
+    (*new)->data = data;
+    (*new)->func = func;
 
     /* First we create the new thread...*/
 	if (attr)
@@ -113,7 +121,7 @@
         return stat;
     }
 
-    (*new)->td = spawn_thread((thread_func)func, "apr thread", temp, data);
+    (*new)->td = spawn_thread((thread_func)dummy_func, "apr thread", temp, (*new));
     /* Now we try to run it...*/
     if (resume_thread((*new)->td) == B_NO_ERROR) {
         return APR_SUCCESS;
@@ -191,3 +199,5 @@
     (*thd)->td = *thethd;
     return APR_SUCCESS;
 }
+
+APR_POOL_IMPLEMENT_ACCESSOR_X(thread, cntxt)
Index: threadproc/os2/thread.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/os2/thread.c,v
retrieving revision 1.22
diff -u -r1.22 thread.c
--- threadproc/os2/thread.c	2001/06/16 01:27:15	1.22
+++ threadproc/os2/thread.c	2001/07/24 00:11:19
@@ -95,7 +95,7 @@
 static void apr_thread_begin(void *arg)
 {
   apr_thread_t *thread = (apr_thread_t *)arg;
-  thread->rv = thread->func(thread->data);
+  thread->rv = thread->func(thread, thread->data);
 }
 
 
@@ -131,13 +131,9 @@
             return stat;
         }
     }
-    
-    if (thread->attr->attr & APR_THREADATTR_DETACHED)
-        thread->tid = _beginthread((os2_thread_start_t)func, NULL, 
-                                   APR_THREAD_STACKSIZE, data);
-    else
-        thread->tid = _beginthread(apr_thread_begin, NULL, 
-                                   APR_THREAD_STACKSIZE, thread);
+
+    thread->tid = _beginthread(apr_thread_begin, NULL, 
+                               APR_THREAD_STACKSIZE, thread);
         
     if (thread->tid < 0) {
         return errno;
@@ -235,3 +231,5 @@
 {
     return apr_pool_userdata_set(data, key, cleanup, thread->cntxt);
 }
+
+APR_POOL_IMPLEMENT_ACCESSOR_X(thread, cntxt)
Index: threadproc/unix/thread.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/unix/thread.c,v
retrieving revision 1.39
diff -u -r1.39 thread.c
--- threadproc/unix/thread.c	2001/06/14 18:52:09	1.39
+++ threadproc/unix/thread.c	2001/07/24 00:11:19
@@ -116,6 +116,12 @@
     return APR_NOTDETACH;
 }
 
+void *dummy_worker(void *opaque)
+{
+    apr_thread_t *thread = (apr_thread_t*)opaque;
+    return thread->func(thread, thread->data);
+}
+
 apr_status_t apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr, 
                              apr_thread_start_t func, void *data, 
                              apr_pool_t *cont)
@@ -136,18 +142,20 @@
     }
 
     (*new)->cntxt = cont;
-
+    (*new)->data = data;
+    (*new)->func = func;
+    
     if (attr)
         temp = attr->attr;
     else
         temp = NULL;
-    
+
     stat = apr_pool_create(&(*new)->cntxt, cont);
     if (stat != APR_SUCCESS) {
         return stat;
     }
 
-    if ((stat = pthread_create((*new)->td, temp, func, data)) == 0) {
+    if ((stat = pthread_create((*new)->td, temp, dummy_worker, (*new))) == 0) {
         return APR_SUCCESS;
     }
     else {
@@ -240,6 +248,9 @@
     (*thd)->td = thethd;
     return APR_SUCCESS;
 }
+
+APR_POOL_IMPLEMENT_ACCESSOR_X(thread, cntxt)
+
 #endif  /* HAVE_PTHREAD_H */
 #endif  /* APR_HAS_THREADS */
 
Index: threadproc/win32/thread.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/win32/thread.c,v
retrieving revision 1.32
diff -u -r1.32 thread.c
--- threadproc/win32/thread.c	2001/07/06 14:20:03	1.32
+++ threadproc/win32/thread.c	2001/07/24 00:11:19
@@ -89,6 +89,12 @@
     return APR_NOTDETACH;
 }
 
+void *dummy_func(void *opaque)
+{
+    apr_thread_t *thd = (apr_thread_t *)opaque;
+    return thd->func(thd, thd->data);
+}
+
 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
                                             apr_threadattr_t *attr,
                                             apr_thread_start_t func,
@@ -105,6 +111,8 @@
     }
 
     (*new)->cntxt = cont;
+    (*new)->data = data;
+    (*new)->func = func;
     
     stat = apr_pool_create(&(*new)->cntxt, cont);
     if (stat != APR_SUCCESS) {
@@ -114,8 +122,8 @@
     /* Use 0 for Thread Stack Size, because that will default the stack to the
      * same size as the calling thread. 
      */
-    if (((*new)->td = (HANDLE *)_beginthreadex(NULL, 0, (unsigned int (APR_THREAD_FUNC
*)(void *))func,
-                                               data, 0, &temp)) == 0) {
+    if (((*new)->td = (HANDLE *)_beginthreadex(NULL, 0, (unsigned int (APR_THREAD_FUNC
*)(void *))dummy_func,
+                                               (*new), 0, &temp)) == 0) {
         lasterror = apr_get_os_error();
         return APR_EEXIST; 
         /* MSVC++ doc doesn't mention any additional error info 
@@ -207,3 +215,4 @@
     return APR_SUCCESS;
 }
 
+APR_POOL_IMPLEMENT_ACCESSOR_X(thread, cntxt)


Mime
View raw message