Author: mturk
Date: Wed Apr 22 12:17:44 2009
New Revision: 767480

URL: http://svn.apache.org/viewvc?rev=767480&view=rev
Log:
Sync access to the Pointer and Descriptor from the native

Modified:
    commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c?rev=767480&r1=767479&r2=767480&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Wed Apr 
22 12:17:44 2009
@@ -175,6 +175,13 @@
         jniptr p = GET_IFIELD_P(0001, _O);
         jniptr c = GET_IFIELD_P(0002, _O);
 
+        if ((*_E)->MonitorEnter(_E, _O)) {
+            /* Object locking failed */
+            return ACR_ENOLOCK;
+        }
+        i = GET_IFIELD_I(0000, _O);
+        p = GET_IFIELD_P(0001, _O);
+        c = GET_IFIELD_P(0002, _O);
         if (p) {
             SET_IFIELD_P(0001, _O, 0);
         }
@@ -184,6 +191,7 @@
         if (i >= 0) {
             SET_IFIELD_I(0000, _O, -1);
         }
+        (*_E)->MonitorExit(_E, _O);
 
         callback = (acr_descriptor_callback_fn_t *)((acr_ptr_t)c);
         if (callback) {
@@ -229,14 +237,18 @@
 ACR_DECLARE(int) ACR_DescriptorSetPtr(ACR_JNISTDARGS, void *p)
 {
     if (_clazzn.i && J4MID(0000)) {
+        if ((*_E)->MonitorEnter(_E, _O)) {
+            /* Object locking failed */
+            return ACR_ENOLOCK;
+        }
         SET_IFIELD_P(0001, _O, (jniptr)((acr_ptr_t)p));
 #ifdef _JNI_CHECK_EXCEPTIONS
         if ((*_E)->ExceptionCheck(_E)) {
             return ACR_EGENERAL;
         }
-        else
 #endif
-            return ACR_SUCCESS;
+        (*_E)->MonitorExit(_E, _O);
+        return ACR_SUCCESS;
     }
     else {
         return ACR_ECLASSNOTFOUND;
@@ -246,14 +258,18 @@
 ACR_DECLARE(int) ACR_DescriptorSetInt(ACR_JNISTDARGS, int i)
 {
     if (_clazzn.i && J4MID(0000)) {
+        if ((*_E)->MonitorEnter(_E, _O)) {
+            /* Object locking failed */
+            return ACR_ENOLOCK;
+        }
         SET_IFIELD_I(0000, _O, i);
 #ifdef _JNI_CHECK_EXCEPTIONS
         if ((*_E)->ExceptionCheck(_E)) {
             return ACR_EGENERAL;
         }
-        else
 #endif
-            return ACR_SUCCESS;
+        (*_E)->MonitorExit(_E, _O);
+        return ACR_SUCCESS;
     }
     else {
         return ACR_ECLASSNOTFOUND;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=767480&r1=767479&r2=767480&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Wed Apr 22 
12:17:44 2009
@@ -161,15 +161,22 @@
 {
     if (_clazzn.i && J4MID(0000) && _O) {
         acr_pointer_cleanup_fn_t *cleanup;
-        jniptr h = GET_IFIELD_P(0000, _O);
-        jniptr c = GET_IFIELD_P(0001, _O);
+        jniptr h;
+        jniptr c;
 
+        if ((*_E)->MonitorEnter(_E, _O)) {
+            /* Object locking failed */
+            return ACR_ENOLOCK;
+        }
+        h = GET_IFIELD_P(0000, _O);
+        c = GET_IFIELD_P(0001, _O);
         if (h) {
             SET_IFIELD_P(0000, _O, 0);
         }
         if (c) {
             SET_IFIELD_P(0001, _O, 0);
         }
+        (*_E)->MonitorExit(_E, _O);
         cleanup = (acr_pointer_cleanup_fn_t *)((acr_ptr_t)c);
         if (cleanup) {
             int rc = (*cleanup)((void *)((acr_ptr_t)h));
@@ -206,6 +213,11 @@
 ACR_DECLARE(int) ACR_PointerSet(ACR_JNISTDARGS, void *p, size_t len)
 {
     if (_clazzn.i && J4MID(0000) && _O) {
+        if ((*_E)->MonitorEnter(_E, _O)) {
+            /* Object locking failed */
+            return ACR_ENOLOCK;
+        }
+
         SET_IFIELD_P(0000, _O, (jniptr)((acr_ptr_t)p));
 #ifdef _JNI_CHECK_EXCEPTIONS
         if ((*_E)->ExceptionCheck(_E)) {
@@ -220,6 +232,7 @@
             }
 #endif
         }
+        (*_E)->MonitorExit(_E, _O);
         return ACR_SUCCESS;
     }
     else {


Reply via email to