You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/17 19:56:25 UTC

svn commit: r816307 - in /commons/sandbox/runtime/trunk/src/main/native/os: unix/main.c win32/main.c

Author: mturk
Date: Thu Sep 17 17:56:24 2009
New Revision: 816307

URL: http://svn.apache.org/viewvc?rev=816307&view=rev
Log:
Make sure we allways have id for TLSD

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c?rev=816307&r1=816306&r2=816307&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c Thu Sep 17 17:56:24 2009
@@ -142,16 +142,11 @@
     acr_tlsd_data_t    *node;
     acr_thread_local_t *tlsd;
 
-    tlsd = (acr_thread_local_t *)pthread_getspecific(acr_thread_key);
-    if (tlsd == NULL) {
-        tlsd = x_calloc(sizeof(acr_thread_local_t));
-        if (tlsd == NULL) {
-            return ACR_GET_OS_ERROR();
-        }
-        else {
-            ACR_RING_INIT(&tlsd->data_ring, acr_tlsd_data_t, link);
-            pthread_setspecific(acr_thread_key, tlsd);
-        }
+    tlsd = ACR_TLSD();
+    if (tlsd == &_null_tlsd) {
+        /* We cannot add to null TLSD
+         */
+        return ACR_ENOMEM;
     }
     for (node  = ACR_RING_FIRST(&(tlsd->data_ring));
          node != ACR_RING_SENTINEL(&(tlsd->data_ring), acr_tlsd_data_t, link);
@@ -181,6 +176,12 @@
         return NULL;
     }
     tlsd = ACR_TLSD();
+    if (tlsd == &_null_tlsd) {
+        /* We cannot get JNIEnv inside null TLSD
+         */
+        ACR_SET_OS_ERROR(ACR_ENOMEM);
+        return NULL;
+    }
     if (tlsd->env == NULL) {
         if ((*acr_pvm)->GetEnv(acr_pvm, &epp,
                                JNI_VERSION_1_4) == JNI_EDETACHED) {

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=816307&r1=816306&r2=816307&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Thu Sep 17 17:56:24 2009
@@ -404,6 +404,7 @@
             return &_null_tlsd;
         }
         else {
+            tlsd->id = (unsigned int)InterlockedIncrement(&acr_thread_id_cur);
             TlsSetValue(dll_tls_index, tlsd);
             return tlsd;
         }
@@ -417,23 +418,12 @@
     acr_tlsd_data_t    *node;
     acr_thread_local_t *tlsd;
 
-    if (dll_tls_index == TLS_OUT_OF_INDEXES) {
-        /* Adding data whild being destoyed */
+    tlsd = ACR_TLSD();
+    if (tlsd == &null_tlsd) {
+        /* We cannot add to null TLSD
+         */
         return ACR_ENOMEM;
     }
-    tlsd = (acr_thread_local_t *)TlsGetValue(dll_tls_index);
-    if (tlsd == NULL) {
-        if (GetLastError() != ERROR_SUCCESS)
-            return ACR_GET_OS_ERROR();
-        tlsd = ACR_HeapCalloc(sizeof(acr_thread_local_t));
-        if (tlsd == NULL) {
-            return ACR_ENOMEM;
-        }
-        else {
-            ACR_RING_INIT(&tlsd->data_ring, acr_tlsd_data_t, link);
-            TlsSetValue(dll_tls_index, tlsd);
-        }
-    }
     else {
         /* Check if we have added this pointer already
          */
@@ -465,13 +455,11 @@
         ACR_SET_OS_ERROR(ACR_INCOMPLETE);
         return NULL;
     }
-    if (dll_tls_index == TLS_OUT_OF_INDEXES) {
-        ACR_SET_OS_ERROR(ACR_ENOMEM);
-        return NULL;
-    }
     tlsd = ACR_TLSD();
     if (tlsd == &_null_tlsd) {
-        /* Errno is already set */
+        /* We cannot get JNIEnv inside null TLSD
+         */
+        ACR_SET_OS_ERROR(ACR_ENOMEM);
         return NULL;
     }
     if (tlsd->env == NULL) {
@@ -479,7 +467,6 @@
                                JNI_VERSION_1_4) == JNI_EDETACHED) {
             char tn[32];
             JavaVMAttachArgs aa;
-            tlsd->id = (unsigned int)InterlockedIncrement(&acr_thread_id_cur);
             sprintf(tn, "ACR Native Thread %u", tlsd->id);
             aa.version = JNI_VERSION_1_4;
             aa.name    = tn;