You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by va...@apache.org on 2008/01/30 07:04:25 UTC

svn commit: r616645 - in /harmony/enhanced/drlvm/trunk/make: extra/ resources/patches/ resources/patches/apr/ resources/patches/apr/include/ resources/patches/apr/include/arch/ resources/patches/apr/include/arch/win32/ resources/patches/apr/locks/ reso...

Author: varlax
Date: Tue Jan 29 22:04:23 2008
New Revision: 616645

URL: http://svn.apache.org/viewvc?rev=616645&view=rev
Log:
Added APR sources patching

Added:
    harmony/enhanced/drlvm/trunk/make/resources/patches/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/include/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/include/arch/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/include/arch/win32/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/include/arch/win32/apr_arch_thread_cond.h   (with props)
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/locks/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/locks/win32/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/locks/win32/thread_cond.c   (with props)
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/misc/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/misc/win32/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/misc/win32/env.c   (with props)
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/unix/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/unix/thread.c   (with props)
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/win32/
    harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/win32/thread.c   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/make/extra/apr.xml

Modified: harmony/enhanced/drlvm/trunk/make/extra/apr.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/make/extra/apr.xml?rev=616645&r1=616644&r2=616645&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/make/extra/apr.xml (original)
+++ harmony/enhanced/drlvm/trunk/make/extra/apr.xml Tue Jan 29 22:04:23 2008
@@ -34,6 +34,9 @@
         <mkdir dir="${apr.src}/.." />
         <untar src="${apr.src.tgz}" dest="${apr.src}/.." compression="gzip"/>
         <move tofile="${apr.src}" file="${apr.src}/../${apr.src.rootdir}"/>
+        <copy todir="${apr.src}" overwrite="true">
+            <fileset dir="${drlvm.base.dir}/make/resources/patches/apr"/>
+        </copy>
     </target>
 
     <target name="-setup">

Added: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/include/arch/win32/apr_arch_thread_cond.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/make/resources/patches/apr/include/arch/win32/apr_arch_thread_cond.h?rev=616645&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/make/resources/patches/apr/include/arch/win32/apr_arch_thread_cond.h (added)
+++ harmony/enhanced/drlvm/trunk/make/resources/patches/apr/include/arch/win32/apr_arch_thread_cond.h Tue Jan 29 22:04:23 2008
@@ -0,0 +1,42 @@
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef THREAD_COND_H
+#define THREAD_COND_H
+
+#include "apr_thread_cond.h"
+
+
+struct waiting_node {
+   // notification event
+   HANDLE event;
+   // double-linked queue
+   struct waiting_node *prev;
+   struct waiting_node *next;
+};
+
+// queue based condition implementation
+struct apr_thread_cond_t {
+    apr_pool_t *pool;
+    // the signal, could be called without mutex
+    // so we use internal one to guard the waiting queue
+    apr_thread_mutex_t *queue_mutex;
+    // head-tail marker node
+    struct waiting_node dummy_node;
+};
+
+#endif  /* THREAD_COND_H */
+

Propchange: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/include/arch/win32/apr_arch_thread_cond.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/locks/win32/thread_cond.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/make/resources/patches/apr/locks/win32/thread_cond.c?rev=616645&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/make/resources/patches/apr/locks/win32/thread_cond.c (added)
+++ harmony/enhanced/drlvm/trunk/make/resources/patches/apr/locks/win32/thread_cond.c Tue Jan 29 22:04:23 2008
@@ -0,0 +1,169 @@
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr.h"
+#include "apr_private.h"
+#include "apr_general.h"
+#include "apr_strings.h"
+#include "win32/apr_arch_thread_mutex.h"
+#include "win32/apr_arch_thread_cond.h"
+#include "apr_portable.h"
+
+// define this constants to synchronized waiting queue access
+// it is neccessery becuase signal() is not requiried to hold mutex
+#define LOCK_QUEUE apr_thread_mutex_lock(cond->queue_mutex)
+#define UNLOCK_QUEUE apr_thread_mutex_unlock(cond->queue_mutex)
+
+static apr_status_t thread_cond_cleanup(void *data)
+{
+    apr_thread_mutex_destroy(((apr_thread_cond_t *)data)->queue_mutex);
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
+                                                 apr_pool_t *pool)
+{
+    *cond = apr_pcalloc(pool, sizeof(**cond));
+    (*cond)->pool = pool;
+    (*cond)-> dummy_node.next = (*cond)-> dummy_node.prev =  &((*cond)-> dummy_node);
+    apr_thread_mutex_create(&((*cond)->queue_mutex),  APR_THREAD_MUTEX_NESTED, pool);
+    return APR_SUCCESS;
+}
+
+static void _enqueue (apr_thread_cond_t *cond, struct waiting_node *node) {
+     node->next = &(cond->dummy_node);
+     node->prev = cond->dummy_node.prev;
+     node->prev->next = node;
+     cond->dummy_node.prev = node;
+
+}
+
+static int _remove_from_queue (apr_thread_cond_t *cond, struct waiting_node *node) {
+    if (node->next == NULL || node->prev == NULL) {
+        // already dequeued (by signal)
+        return -1;
+    }
+    node->prev->next = node->next;
+    node->next->prev = node->prev;
+    node->next = NULL; 
+    node->prev = NULL;
+    return 0;
+}
+
+//dequeue 
+// return NULL if queue is empty
+static struct waiting_node* _dequeue (apr_thread_cond_t *cond) {
+    struct waiting_node* node;
+    if (cond->dummy_node.next == &(cond->dummy_node)) {
+        // the queue is empty
+        return NULL;
+    }
+    node=cond->dummy_node.next;
+    _remove_from_queue (cond,node);
+    return node;
+}
+static APR_INLINE apr_status_t _thread_cond_timedwait(apr_thread_cond_t *cond,
+                                                      apr_thread_mutex_t *mutex,
+                                                      DWORD timeout_ms )
+{
+    DWORD res;
+    apr_status_t rv = APR_SUCCESS;
+    struct waiting_node node;
+
+    // add waiting
+    node.event = CreateEvent(NULL, TRUE, FALSE, NULL);
+    LOCK_QUEUE;
+    _enqueue (cond, &node);
+    UNLOCK_QUEUE;
+
+    // release mutex and wait for signal 
+    apr_thread_mutex_unlock(mutex);
+    res = WaitForSingleObject(node.event, timeout_ms);
+    if (res != WAIT_OBJECT_0) {
+        if (res == WAIT_TIMEOUT) {
+            rv = APR_TIMEUP;
+        } else {
+            rv = apr_get_os_error();
+        }
+    }
+    apr_thread_mutex_lock(mutex);
+    LOCK_QUEUE;
+    _remove_from_queue (cond, &node);
+    CloseHandle(node.event);
+    UNLOCK_QUEUE;
+
+    return rv;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
+                                               apr_thread_mutex_t *mutex)
+{
+    return _thread_cond_timedwait(cond, mutex, INFINITE);
+}
+
+APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
+                                                    apr_thread_mutex_t *mutex,
+                                                    apr_interval_time_t timeout)
+{
+    DWORD timeout_ms = (DWORD) apr_time_as_msec(timeout);
+    if (timeout % 1000) {
+        timeout_ms++;
+    }  
+    return _thread_cond_timedwait(cond, mutex, timeout_ms);
+}
+
+APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
+{
+    apr_status_t rv = APR_SUCCESS;
+    DWORD res;
+    struct waiting_node* node;
+
+    LOCK_QUEUE;
+    node = _dequeue (cond);
+    if (node != NULL) {
+        res = SetEvent(node->event);
+        if (res == 0) {
+             rv = apr_get_os_error();
+        }
+    }
+    UNLOCK_QUEUE;
+    return rv;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
+{
+    apr_status_t rv = APR_SUCCESS;
+    DWORD res;
+    struct waiting_node* node;
+
+    LOCK_QUEUE;
+    for (node = _dequeue (cond); node != NULL; node = _dequeue (cond)) {
+        res = SetEvent(node->event);
+        if (res == 0) {
+              rv = apr_get_os_error();
+        }
+    }
+    UNLOCK_QUEUE;
+    return rv;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
+{
+    return apr_pool_cleanup_run(cond->pool, cond, thread_cond_cleanup);
+}
+
+APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
+

Propchange: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/locks/win32/thread_cond.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/misc/win32/env.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/make/resources/patches/apr/misc/win32/env.c?rev=616645&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/make/resources/patches/apr/misc/win32/env.c (added)
+++ harmony/enhanced/drlvm/trunk/make/resources/patches/apr/misc/win32/env.c Tue Jan 29 22:04:23 2008
@@ -0,0 +1,184 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define APR_WANT_STRFUNC
+#include "apr_want.h"
+#include "apr.h"
+#include "apr_arch_misc.h"
+#include "apr_arch_utf8.h"
+#include "apr_env.h"
+#include "apr_errno.h"
+#include "apr_pools.h"
+#include "apr_strings.h"
+
+
+#if APR_HAS_UNICODE_FS
+static apr_status_t widen_envvar_name (apr_wchar_t *buffer,
+                                       apr_size_t bufflen,
+                                       const char *envvar)
+{
+    apr_size_t inchars;
+    apr_status_t status;
+
+    inchars = strlen(envvar) + 1;
+    status = apr_conv_utf8_to_ucs2(envvar, &inchars, buffer, &bufflen);
+    if (status == APR_INCOMPLETE)
+        status = APR_ENAMETOOLONG;
+
+    return status;
+}
+#endif
+
+
+APR_DECLARE(apr_status_t) apr_env_get(char **value,
+                                      const char *envvar,
+                                      apr_pool_t *pool)
+{
+    char *val = NULL;
+    DWORD size;
+
+#if APR_HAS_UNICODE_FS
+    IF_WIN_OS_IS_UNICODE
+    {
+        apr_wchar_t wenvvar[APR_PATH_MAX];
+        apr_size_t inchars, outchars;
+        apr_wchar_t *wvalue, dummy;
+        apr_status_t status;
+
+        status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
+        if (status)
+            return status;
+
+        SetLastError(0);
+        size = GetEnvironmentVariableW(wenvvar, &dummy, 0);
+        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+            /* The environment variable doesn't exist. */
+            return APR_ENOENT;
+
+        if (size == 0) {
+            /* The environment value exists, but is zero-length. */
+            *value = apr_pstrdup(pool, "");
+            return APR_SUCCESS;
+        }
+
+        wvalue = apr_palloc(pool, size * sizeof(*wvalue));
+        size = GetEnvironmentVariableW(wenvvar, wvalue, size);
+        if (size == 0)
+            /* Mid-air collision?. Somebody must've changed the env. var. */
+            return APR_INCOMPLETE;
+
+        inchars = wcslen(wvalue) + 1;
+        outchars = 3 * inchars; /* Enougn for any UTF-8 representation */
+        val = apr_palloc(pool, outchars);
+        status = apr_conv_ucs2_to_utf8(wvalue, &inchars, val, &outchars);
+        if (status)
+            return status;
+    }
+#endif
+#if APR_HAS_ANSI_FS
+    ELSE_WIN_OS_IS_ANSI
+    {
+        char dummy;
+
+        SetLastError(0);
+        size = GetEnvironmentVariableA(envvar, &dummy, 0);
+        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+            /* The environment variable doesn't exist. */
+            return APR_ENOENT;
+
+        if (size == 0) {
+            /* The environment value exists, but is zero-length. */
+            *value = apr_pstrdup(pool, "");
+            return APR_SUCCESS;
+        }
+
+        val = apr_palloc(pool, size);
+        size = GetEnvironmentVariableA(envvar, val, size);
+        if (size == 0)
+            /* Mid-air collision?. Somebody must've changed the env. var. */
+            return APR_INCOMPLETE;
+    }
+#endif
+
+    *value = val;
+    return APR_SUCCESS;
+}
+
+
+APR_DECLARE(apr_status_t) apr_env_set(const char *envvar,
+                                      const char *value,
+                                      apr_pool_t *pool)
+{
+#if APR_HAS_UNICODE_FS
+    IF_WIN_OS_IS_UNICODE
+    {
+        apr_wchar_t wenvvar[APR_PATH_MAX];
+        apr_wchar_t *wvalue;
+        apr_size_t inchars, outchars;
+        apr_status_t status;
+
+        status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
+        if (status)
+            return status;
+
+        outchars = inchars = strlen(value) + 1;
+        wvalue = apr_palloc(pool, outchars * sizeof(*wvalue));
+        status = apr_conv_utf8_to_ucs2(value, &inchars, wvalue, &outchars);
+        if (status)
+            return status;
+
+        if (!SetEnvironmentVariableW(wenvvar, wvalue))
+            return apr_get_os_error();
+    }
+#endif
+#if APR_HAS_ANSI_FS
+    ELSE_WIN_OS_IS_ANSI
+    {
+        if (!SetEnvironmentVariableA(envvar, value))
+            return apr_get_os_error();
+    }
+#endif
+
+    return APR_SUCCESS;
+}
+
+
+APR_DECLARE(apr_status_t) apr_env_delete(const char *envvar, apr_pool_t *pool)
+{
+#if APR_HAS_UNICODE_FS
+    IF_WIN_OS_IS_UNICODE
+    {
+        apr_wchar_t wenvvar[APR_PATH_MAX];
+        apr_status_t status;
+
+        status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
+        if (status)
+            return status;
+
+        if (!SetEnvironmentVariableW(wenvvar, NULL))
+            return apr_get_os_error();
+    }
+#endif
+#if APR_HAS_ANSI_FS
+    ELSE_WIN_OS_IS_ANSI
+    {
+        if (!SetEnvironmentVariableA(envvar, NULL))
+            return apr_get_os_error();
+    }
+#endif
+
+    return APR_SUCCESS;
+}

Propchange: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/misc/win32/env.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/unix/thread.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/unix/thread.c?rev=616645&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/unix/thread.c (added)
+++ harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/unix/thread.c Tue Jan 29 22:04:23 2008
@@ -0,0 +1,321 @@
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr.h"
+#include "apr_portable.h"
+#include "apr_arch_threadproc.h"
+
+#if APR_HAS_THREADS
+
+#if APR_HAVE_PTHREAD_H
+
+/* Destroy the threadattr object */
+static apr_status_t threadattr_cleanup(void *data)
+{
+    apr_threadattr_t *attr = data;
+    apr_status_t rv;
+
+    rv = pthread_attr_destroy(&attr->attr);
+#ifdef PTHREAD_SETS_ERRNO
+    if (rv) {
+        rv = errno;
+    }
+#endif
+    return rv;
+}
+
+APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new,
+                                                apr_pool_t *pool)
+{
+    apr_status_t stat;
+
+    (*new) = apr_palloc(pool, sizeof(apr_threadattr_t));
+    (*new)->pool = pool;
+    stat = pthread_attr_init(&(*new)->attr);
+
+    if (stat == 0) {
+        apr_pool_cleanup_register(pool, *new, threadattr_cleanup,
+                                  apr_pool_cleanup_null);
+        return APR_SUCCESS;
+    }
+#ifdef PTHREAD_SETS_ERRNO
+    stat = errno;
+#endif
+
+    return stat;
+}
+
+#define DETACH_ARG(v) ((v) ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE)
+
+APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr,
+                                                    apr_int32_t on)
+{
+    apr_status_t stat;
+#ifdef PTHREAD_ATTR_SETDETACHSTATE_ARG2_ADDR
+    int arg = DETACH_ARG(v);
+
+    if ((stat = pthread_attr_setdetachstate(&attr->attr, &arg)) == 0) {
+#else
+    if ((stat = pthread_attr_setdetachstate(&attr->attr, 
+                                            DETACH_ARG(on))) == 0) {
+#endif
+        return APR_SUCCESS;
+    }
+    else {
+#ifdef PTHREAD_SETS_ERRNO
+        stat = errno;
+#endif
+
+        return stat;
+    }
+}
+
+APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr)
+{
+    int state;
+
+#ifdef PTHREAD_ATTR_GETDETACHSTATE_TAKES_ONE_ARG
+    state = pthread_attr_getdetachstate(&attr->attr);
+#else
+    pthread_attr_getdetachstate(&attr->attr, &state);
+#endif
+    if (state == 1)
+        return APR_DETACH;
+    return APR_NOTDETACH;
+}
+
+APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
+                                                       apr_size_t stacksize)
+{
+    int stat;
+
+    stat = pthread_attr_setstacksize(&attr->attr, stacksize);
+    if (stat == 0) {
+        return APR_SUCCESS;
+    }
+#ifdef PTHREAD_SETS_ERRNO
+    stat = errno;
+#endif
+
+    return stat;
+}
+
+APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
+                                                       apr_size_t size)
+{
+#ifdef HAVE_PTHREAD_ATTR_SETGUARDSIZE
+    apr_status_t rv;
+
+    rv = pthread_attr_setguardsize(&attr->attr, size);
+    if (rv == 0) {
+        return APR_SUCCESS;
+    }
+#ifdef PTHREAD_SETS_ERRNO
+    rv = errno;
+#endif
+    return rv;
+#else
+    return APR_ENOTIMPL;
+#endif
+}
+
+static void *dummy_worker(void *opaque)
+{
+    apr_thread_t *thread = (apr_thread_t*)opaque;
+    return thread->func(thread, thread->data);
+}
+
+APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
+                                            apr_threadattr_t *attr,
+                                            apr_thread_start_t func,
+                                            void *data,
+                                            apr_pool_t *pool)
+{
+    apr_status_t stat;
+    pthread_attr_t *temp;
+
+    (*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
+
+    if ((*new) == NULL) {
+        return APR_ENOMEM;
+    }
+
+    (*new)->td = (pthread_t *)apr_pcalloc(pool, sizeof(pthread_t));
+
+    if ((*new)->td == NULL) {
+        return APR_ENOMEM;
+    }
+
+    (*new)->pool = pool;
+    (*new)->data = data;
+    (*new)->func = func;
+
+    if (attr)
+        temp = &attr->attr;
+    else
+        temp = NULL;
+
+    stat = apr_pool_create(&(*new)->pool, pool);
+    if (stat != APR_SUCCESS) {
+        return stat;
+    }
+
+    if ((stat = pthread_create((*new)->td, temp, dummy_worker, (*new))) == 0) {
+        return APR_SUCCESS;
+    }
+    else {
+#ifdef PTHREAD_SETS_ERRNO
+        stat = errno;
+#endif
+
+        return stat;
+    }
+}
+
+APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
+{
+    return pthread_self();
+}
+
+APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1,
+                                     apr_os_thread_t tid2)
+{
+    return pthread_equal(tid1, tid2);
+}
+
+APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
+                                          apr_status_t retval)
+{
+    thd->exitval = retval;
+    apr_pool_destroy(thd->pool);
+    pthread_exit(NULL);
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
+                                          apr_thread_t *thd)
+{
+    apr_status_t stat;
+    apr_status_t *thread_stat;
+
+    if ((stat = pthread_join(*thd->td,(void *)&thread_stat)) == 0) {
+        *retval = thd->exitval;
+        return APR_SUCCESS;
+    }
+    else {
+#ifdef PTHREAD_SETS_ERRNO
+        stat = errno;
+#endif
+
+        return stat;
+    }
+}
+
+APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)
+{
+    apr_status_t stat;
+
+#ifdef PTHREAD_DETACH_ARG1_ADDR
+    if ((stat = pthread_detach(thd->td)) == 0) {
+#else
+    if ((stat = pthread_detach(*thd->td)) == 0) {
+#endif
+
+        return APR_SUCCESS;
+    }
+    else {
+#ifdef PTHREAD_SETS_ERRNO
+        stat = errno;
+#endif
+
+        return stat;
+    }
+}
+
+void apr_thread_yield()
+{
+    sched_yield();
+}
+
+APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
+                                              apr_thread_t *thread)
+{
+    return apr_pool_userdata_get(data, key, thread->pool);
+}
+
+APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
+                              apr_status_t (*cleanup)(void *),
+                              apr_thread_t *thread)
+{
+    return apr_pool_userdata_set(data, key, cleanup, thread->pool);
+}
+
+APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd,
+                                            apr_thread_t *thd)
+{
+    *thethd = thd->td;
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd,
+                                            apr_os_thread_t *thethd,
+                                            apr_pool_t *pool)
+{
+    if (pool == NULL) {
+        return APR_ENOPOOL;
+    }
+
+    if ((*thd) == NULL) {
+        (*thd) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
+        (*thd)->pool = pool;
+    }
+
+    (*thd)->td = thethd;
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
+                                               apr_pool_t *p)
+{
+    static const pthread_once_t once_init = PTHREAD_ONCE_INIT;
+
+    *control = apr_palloc(p, sizeof(**control));
+    (*control)->once = once_init;
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
+                                          void (*func)(void))
+{
+    return pthread_once(&control->once, func);
+}
+
+APR_POOL_IMPLEMENT_ACCESSOR(thread)
+
+#endif  /* HAVE_PTHREAD_H */
+#endif  /* APR_HAS_THREADS */
+
+#if !APR_HAS_THREADS
+
+/* avoid warning for no prototype */
+APR_DECLARE(apr_status_t) apr_os_thread_get(void);
+
+APR_DECLARE(apr_status_t) apr_os_thread_get(void)
+{
+    return APR_ENOTIMPL;
+}
+
+#endif

Propchange: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/unix/thread.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/win32/thread.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/win32/thread.c?rev=616645&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/win32/thread.c (added)
+++ harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/win32/thread.c Tue Jan 29 22:04:23 2008
@@ -0,0 +1,282 @@
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr_private.h"
+#include "win32/apr_arch_threadproc.h"
+#include "apr_thread_proc.h"
+#include "apr_general.h"
+#include "apr_lib.h"
+#include "apr_portable.h"
+#if APR_HAVE_PROCESS_H
+#include <process.h>
+#endif
+#include "apr_arch_misc.h"   
+
+/* Chosen for us by apr_initialize */
+DWORD tls_apr_thread = 0;
+
+APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new,
+                                                apr_pool_t *pool)
+{
+    (*new) = (apr_threadattr_t *)apr_palloc(pool, 
+              sizeof(apr_threadattr_t));
+
+    if ((*new) == NULL) {
+        return APR_ENOMEM;
+    }
+
+    (*new)->pool = pool;
+    (*new)->detach = 0;
+    (*new)->stacksize = 0;
+
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr,
+                                                   apr_int32_t on)
+{
+    attr->detach = on;
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr)
+{
+    if (attr->detach == 1)
+        return APR_DETACH;
+    return APR_NOTDETACH;
+}
+
+APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
+                                                       apr_size_t stacksize)
+{
+    attr->stacksize = stacksize;
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
+                                                       apr_size_t size)
+{
+    return APR_ENOTIMPL;
+}
+
+static void *dummy_worker(void *opaque)
+{
+    apr_thread_t *thd = (apr_thread_t *)opaque;
+    TlsSetValue(tls_apr_thread, thd->td);
+    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,
+                                            void *data, apr_pool_t *pool)
+{
+    apr_status_t stat;
+	unsigned temp;
+    HANDLE handle;
+
+    (*new) = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t));
+
+    if ((*new) == NULL) {
+        return APR_ENOMEM;
+    }
+
+    (*new)->pool = pool;
+    (*new)->data = data;
+    (*new)->func = func;
+    (*new)->td   = NULL;
+    stat = apr_pool_create(&(*new)->pool, pool);
+    if (stat != APR_SUCCESS) {
+        return stat;
+    }
+
+    /* Use 0 for Thread Stack Size, because that will default the stack to the
+     * same size as the calling thread. 
+     */
+#ifndef _WIN32_WCE
+    if ((handle = (HANDLE)_beginthreadex(NULL,
+                        attr && attr->stacksize > 0 ? attr->stacksize : 0,
+                        (unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker,
+                        (*new), 0, &temp)) == 0) {
+        return APR_FROM_OS_ERROR(_doserrno);
+    }
+#else
+   if ((handle = CreateThread(NULL,
+                        attr && attr->stacksize > 0 ? attr->stacksize : 0,
+                        (unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker,
+                        (*new), 0, &temp)) == 0) {
+        return apr_get_os_error();
+    }
+#endif
+    if (attr && attr->detach) {
+        CloseHandle(handle);
+    }
+    else
+        (*new)->td = handle;
+
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
+                                          apr_status_t retval)
+{
+    thd->exitval = retval;
+    apr_pool_destroy(thd->pool);
+    thd->pool = NULL;
+#ifndef _WIN32_WCE
+    _endthreadex(0);
+#else
+    ExitThread(0);
+#endif
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
+                                          apr_thread_t *thd)
+{
+    apr_status_t rv = APR_SUCCESS;
+    
+    if (!thd->td) {
+        /* Can not join on detached threads */
+        return APR_DETACH;
+    }
+    rv = WaitForSingleObject(thd->td, INFINITE);
+    if ( rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
+        /* If the thread_exit has been called */
+        if (!thd->pool)
+            *retval = thd->exitval;
+        else
+            rv = APR_INCOMPLETE;
+    }
+    else
+        rv = apr_get_os_error();
+    CloseHandle(thd->td);
+    thd->td = NULL;
+
+    return rv;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)
+{
+    if (thd->td && CloseHandle(thd->td)) {
+        thd->td = NULL;
+        return APR_SUCCESS;
+    }
+    else {
+        return apr_get_os_error();
+    }
+}
+
+APR_DECLARE(void) apr_thread_yield()
+{
+    /* SwitchToThread is not supported on Win9x, but since it's
+     * primarily a noop (entering time consuming code, therefore
+     * providing more critical threads a bit larger timeslice)
+     * we won't worry too much if it's not available.
+     */
+#ifndef _WIN32_WCE
+    if (apr_os_level >= APR_WIN_NT) {
+        SwitchToThread();
+    }
+#endif
+}
+
+APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
+                                             apr_thread_t *thread)
+{
+    return apr_pool_userdata_get(data, key, thread->pool);
+}
+
+APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
+                                             apr_status_t (*cleanup) (void *),
+                                             apr_thread_t *thread)
+{
+    return apr_pool_userdata_set(data, key, cleanup, thread->pool);
+}
+
+
+APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
+{
+    HANDLE hthread = (HANDLE)TlsGetValue(tls_apr_thread);
+    HANDLE hproc;
+
+    if (hthread) {
+        return hthread;
+    }
+    
+    hproc = GetCurrentProcess();
+    hthread = GetCurrentThread();
+    if (!DuplicateHandle(hproc, hthread, 
+                         hproc, &hthread, 0, FALSE, 
+                         DUPLICATE_SAME_ACCESS)) {
+        return NULL;
+    }
+    TlsSetValue(tls_apr_thread, hthread);
+    return hthread;
+}
+
+APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd,
+                                            apr_thread_t *thd)
+{
+    if (thd == NULL) {
+        return APR_ENOTHREAD;
+    }
+    *thethd = &(thd->td);
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd,
+                                            apr_os_thread_t *thethd,
+                                            apr_pool_t *pool)
+{
+    if (pool == NULL) {
+        return APR_ENOPOOL;
+    }
+    if ((*thd) == NULL) {
+        (*thd) = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t));
+        (*thd)->pool = pool;
+    }
+    (*thd)->td = *thethd;
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
+                                               apr_pool_t *p)
+{
+    (*control) = apr_pcalloc(p, sizeof(**control));
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
+                                          void (*func)(void))
+{
+    if (!InterlockedExchange(&control->value, 1)) {
+        func();
+    }
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1,
+                                     apr_os_thread_t tid2)
+{
+    /* Since the only tid's we support our are own, and
+     * apr_os_thread_current returns the identical handle
+     * to the one we created initially, the test is simple.
+     */
+    return (tid1 == tid2);
+}
+
+APR_POOL_IMPLEMENT_ACCESSOR(thread)

Propchange: harmony/enhanced/drlvm/trunk/make/resources/patches/apr/threadproc/win32/thread.c
------------------------------------------------------------------------------
    svn:eol-style = native