[jbossnative-commits] JBoss Native SVN: r1053 - trunk/sight/native/share.

jbossnative-commits at lists.jboss.org jbossnative-commits at lists.jboss.org
Fri Sep 28 04:25:50 EDT 2007


Author: mladen.turk at jboss.com
Date: 2007-09-28 04:25:49 -0400 (Fri, 28 Sep 2007)
New Revision: 1053

Modified:
   trunk/sight/native/share/no.c
   trunk/sight/native/share/proc.c
Log:
Fix JBNATIVE-38 by adding reference counter for long running native ops.

Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c	2007-09-28 07:31:45 UTC (rev 1052)
+++ trunk/sight/native/share/no.c	2007-09-28 08:25:49 UTC (rev 1053)
@@ -207,6 +207,7 @@
 {
     sight_object_t *no = J2P(instance, sight_object_t *);
     jobject object = NULL;
+    apr_uint32_t ref_count;
 
     UNREFERENCED_O;
 
@@ -215,6 +216,12 @@
 #endif
     if (!no)
         return;
+    ref_count = apr_atomic_read32(&no->references);
+    while (ref_count) {
+        apr_thread_yield();
+        ref_count = apr_atomic_read32(&no->references);
+    }
+
     if (no->object) {
         object = (*_E)->NewLocalRef(_E, no->object);
         (*_E)->DeleteWeakGlobalRef(_E, no->object);

Modified: trunk/sight/native/share/proc.c
===================================================================
--- trunk/sight/native/share/proc.c	2007-09-28 07:31:45 UTC (rev 1052)
+++ trunk/sight/native/share/proc.c	2007-09-28 08:25:49 UTC (rev 1053)
@@ -294,13 +294,17 @@
 {
     sight_object_t *no = J2P(instance, sight_object_t *);
     sight_runproc_t *p;
+    apr_status_t rv;
 
     UNREFERENCED_STDARGS;
     if (!no || !no->native)
         return APR_EINVAL;
+    SIGHT_NO_IREF(no);
     p = (sight_runproc_t *)no->native;
-    return (jint)apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
-                               (apr_wait_how_e)waithow);
+    rv = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
+                       (apr_wait_how_e)waithow);
+    SIGHT_NO_DREF(no);
+    return rv;
 }
 
 
@@ -318,6 +322,7 @@
     UNREFERENCED_STDARGS;
     if (!no || !no->native)
         return APR_EINVAL;
+    SIGHT_NO_IREF(no);
     p = (sight_runproc_t *)no->native;
     if (timeout < 0)
         how = APR_WAIT;
@@ -325,9 +330,9 @@
         how = APR_NOWAIT;
     if ((rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
                             how)) != APR_CHILD_NOTDONE)
-        return rc;
+        goto done;
     if (timeout < 1)
-        return rc;
+        goto done;
     timeout_value = timeout * 1000L;
     timeout_interval = timeout_value / 64;
     do {
@@ -338,6 +343,8 @@
         timeout_interval *= 2;
     } while (rc == APR_CHILD_NOTDONE);
 
+done:
+    SIGHT_NO_DREF(no);
     return rc;
 }
 
@@ -358,11 +365,11 @@
     UNREFERENCED_O;
     if (!no || !no->native || !progress)
         return APR_EINVAL;
+    SIGHT_NO_IREF(no);
     p = (sight_runproc_t *)no->native;
-
     if ((rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
                             APR_NOWAIT)) != APR_CHILD_NOTDONE)
-        return rc;
+        goto done;
 
     c = (*_E)->GetObjectClass(_E, progress);
     cb.name   = "progress";
@@ -370,11 +377,13 @@
     cb.object = progress;
     cb.method = (*_E)->GetMethodID(_E, c, cb.name, cb.msig);
     if (!cb.method || (*_E)->ExceptionCheck(_E)) {
-        return APR_EINVAL;
+        rc = APR_EINVAL;
+        goto done;
     }
     cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick, NULL);
     if ((*_E)->ExceptionCheck(_E)) {
-        return APR_FROM_OS_ERROR(EINTR);
+        rc = APR_FROM_OS_ERROR(EINTR);
+        goto done;
     }
 
     if (timeout > 0) {
@@ -402,11 +411,14 @@
         }
         cres = (*_E)->CallIntMethod(_E, cb.object, cb.method, tick++, NULL);
         if ((*_E)->ExceptionCheck(_E)) {
-            return APR_FROM_OS_ERROR(EINTR);
+            rc = APR_FROM_OS_ERROR(EINTR);
+            goto done;
         }
 
     } while (rc == APR_CHILD_NOTDONE);
 
+done:
+    SIGHT_NO_DREF(no);
     return rc;
 }
 




More information about the jbossnative-commits mailing list