rev 518 - trunk/src
SVN User <[email protected]> Thu, 20 May 2004 13:32:04 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-20 13:32:01 -0400 (Thu, 20 May 2004)
New Revision: 518
Modified:
trunk/src/builtins-thread.c
Log:
fixed thread race condition and cleaned up error condition
Modified: trunk/src/builtins-thread.c
===================================================================
--- trunk/src/builtins-thread.c 2004-05-20 17:28:06 UTC (rev 517)
+++ trunk/src/builtins-thread.c 2004-05-20 17:32:01 UTC (rev 518)
@@ -88,22 +88,6 @@
pr_unlock(&thread_registry_lock);
}
-//**************************** register_thread ********************************
-/* New threads must call this first thing, it will release the
- * thread_registry_lock so that other threads can start.
- * Returns the matching thread object */
-obj_p register_thread(apr_thread_t *this_thread)
-{
- obj_p res = new_thread_object;
- pr_thread_p thread_ptr = res->data.ptr;
- thread_ptr->apr_os_thread = apr_os_thread_current();
- thread_ptr->apr_thread = this_thread;
- clist_append(thread_registry, res);
- thread_ptr->running = TRUE;
- pr_unlock(&thread_registry_lock);
- return res;
-}
-
static apr_threadattr_t *thread_attr = NULL;
static apr_pool_t *thread_pool = NULL;
@@ -125,11 +109,6 @@
aprerr = apr_threadattr_detach_set(thread_attr, 1);
IF_APR_ERR("apr_threadattr_detach_set") return NULL;
}
-
- /* Lock this, so we don't start a new thread, until the last one
- * calls register_thread(). */
- pr_lock(&thread_registry_lock);
-
if (thread_obj)
thread_p = thread_obj->data.ptr;
else {
@@ -140,14 +119,36 @@
}
thread_p->ist = new_ist(acc_level);
+ /* Lock this, so we don't start a new thread, until the last one
+ * calls register_thread(). */
+ pr_lock(&thread_registry_lock);
+
new_thread_object = thread_obj;
-
+
aprerr = apr_thread_create(&new_thread, thread_attr, thread_func, thread_data, thread_pool);
- IF_APR_ERR("apr_thread_create") return NULL;
-
+ IF_APR_ERR("apr_thread_create") {
+ pr_unlock(&thread_registry_lock);
+ return NULL;
+ }
return thread_obj;
}
+//**************************** register_thread ********************************
+/* New threads must call this first thing, it will release the
+ * thread_registry_lock so that other threads can start.
+ * Returns the matching thread object */
+obj_p register_thread(apr_thread_t *this_thread)
+{
+ obj_p res = new_thread_object;
+ pr_thread_p thread_ptr = res->data.ptr;
+ thread_ptr->apr_os_thread = apr_os_thread_current();
+ thread_ptr->apr_thread = this_thread;
+ clist_append(thread_registry, res);
+ thread_ptr->running = TRUE;
+ pr_unlock(&thread_registry_lock);
+ return res;
+}
+
//********************************* os_thread_2_apr ***************************
apr_thread_t* os_thread_2_apr(apr_os_thread_t os_thread) {
int i;