commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r820656 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/include/ main/native/include/arch/unix/ main/native/include/arch/windows/ main/native/os/darwin/ main/native/os/hpux/ main/native/os/unix/ ma...
Date Thu, 01 Oct 2009 13:46:49 GMT
Author: mturk
Date: Thu Oct  1 13:46:48 2009
New Revision: 820656

URL: http://svn.apache.org/viewvc?rev=820656&view=rev
Log:
Separate Descriptor.close and Descriptor.finalize

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_io.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/os/darwin/mutex.c
    commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/mutex.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/sema.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c
    commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
Thu Oct  1 13:46:48 2009
@@ -28,6 +28,7 @@
 class Descriptor32 extends Descriptor
 {
 
+    private int     ISVALID;
     private int     IHANDLE;
     private int     PHANDLE;
     private int     HANDLER;
@@ -42,6 +43,7 @@
         IHANDLE = i;
         PHANDLE = l;
         HANDLER = h;
+        ISVALID = 1;
     }
 
     public int fd()
@@ -52,7 +54,7 @@
     public boolean valid()
     {
         // false if both int is negative and pointer is NULL
-        if (IHANDLE < 0 && PHANDLE == 0)
+        if (ISVALID == 0 || (IHANDLE < 0 && PHANDLE == 0))
             return false;
         else
             return true;

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
Thu Oct  1 13:46:48 2009
@@ -28,6 +28,7 @@
 class Descriptor64 extends Descriptor
 {
 
+    private int     ISVALID;
     private int     IHANDLE;
     private long    PHANDLE;
     private long    HANDLER;
@@ -42,6 +43,7 @@
         IHANDLE = i;
         PHANDLE = l;
         HANDLER = h;
+        ISVALID = 1;
     }
 
     public int fd()
@@ -52,7 +54,7 @@
     public boolean valid()
     {
         // true if both int is negative and pointer is NULL
-        if (IHANDLE < 0 && PHANDLE == 0L)
+        if (ISVALID == 0 || (IHANDLE < 0 && PHANDLE == 0L))
             return false;
         else
             return true;

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h Thu Oct  1 13:46:48
2009
@@ -45,6 +45,7 @@
 #define ACR_DT_MASK             0x000000FF
 
 typedef enum {
+    ACR_DESC_FINALIZE,
     ACR_DESC_CLOSE,
     ACR_DESC_SYNC,
     ACR_DESC_FLUSH

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_io.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_io.h?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_io.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_io.h Thu Oct  1 13:46:48 2009
@@ -40,6 +40,16 @@
  */
 ACR_DECLARE(int) ACR_IoClose(JNIEnv *env, int descriptor);
 
+/**
+ * Close the ACR Descriptor handle and free allocated resources.
+ * @param env Current JNI environment
+ * @param descriptor Descriptor handle to close.
+ * @return ACR error code on failure. If env is not NULL the IO exception
+ *         is thrown in case of failure.
+ * @remark The function calls the descriptor cleanup function.
+ */
+ACR_DECLARE(int) ACR_IoClear(JNIEnv *env, int descriptor);
+
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Thu Oct  1
13:46:48 2009
@@ -87,6 +87,7 @@
 #endif
 #endif
 
+#define ACR_IOH_CLEAR   0x8000000
 typedef struct acr_ioh acr_ioh;
 typedef int (acr_ioh_cleanup_fn_t)(void *, int, unsigned int);
 
@@ -104,6 +105,7 @@
 extern int      acr_ioh_open(void *, int, unsigned int, acr_ioh_cleanup_fn_t *);
 extern int      acr_ioh_free(int);
 extern int      acr_ioh_close(int);
+extern int      acr_ioh_clear(int);
 extern void     acr_ioh_cleanup(void);
 
 extern mode_t   ACR_UnixPermsToMode(int);

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Thu Oct
 1 13:46:48 2009
@@ -269,6 +269,7 @@
  * ---------------------------------------------------------------------
  */
 
+#define ACR_IOH_CLEAR   0x8000000
 typedef struct acr_ioh acr_ioh;
 typedef int (acr_ioh_cleanup_fn_t)(void *, int, unsigned int);
 
@@ -286,6 +287,7 @@
 extern int      acr_ioh_open(void *, int, unsigned int, acr_ioh_cleanup_fn_t *);
 extern int      acr_ioh_free(int);
 extern int      acr_ioh_close(int);
+extern int      acr_ioh_clear(int);
 extern void     acr_ioh_cleanup(void);
 
 /** Default number of IO slots

Modified: commons/sandbox/runtime/trunk/src/main/native/os/darwin/mutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/mutex.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/mutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/mutex.c Thu Oct  1 13:46:48 2009
@@ -79,6 +79,7 @@
 
             }
             close(m->filedes);
+            m->filedes = -1;
             rc = ACR_SUCCESS;
         }
         if (m->filename) {
@@ -88,8 +89,10 @@
                     rc = ACR_GET_OS_ERROR();
             }
             x_free((void *)(m->filename));
+            m->filename = NULL;
         }
-        x_free(m);
+        if (flags & ACR_IOH_CLEAR)
+            x_free(m);
         return rc;
     }
     return ACR_EFTYPE;
@@ -317,6 +320,7 @@
             ick.val = 0;
             semctl(m->filedes, 0, IPC_RMID, ick);
             rc = ACR_SUCCESS;
+            m->filedes = -1;
         }
         if (m->filename) {
             if (access(m->filename, F_OK) == 0) {
@@ -325,8 +329,10 @@
                     rc = ACR_GET_OS_ERROR();
             }
             x_free((void *)(m->filename));
+            m->filename = NULL;
         }
-        x_free(m);
+        if (flags & ACR_IOH_CLEAR)
+            x_free(m);
         return rc;
     }
     return ACR_EFTYPE;
@@ -349,8 +355,10 @@
                 } while (rc < 0 && errno == EINTR);
             }
             rc = ACR_SUCCESS;
+            m->filedes = -1;
         }
-        x_free(m);
+        if (flags & ACR_IOH_CLEAR)
+            x_free(m);
         return rc;
     }
     return ACR_EBADF;
@@ -663,7 +671,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EFTYPE;
     }
-    rc = acr_ioh_close(mutex);
+    rc = acr_ioh_clear(mutex);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }
@@ -690,6 +698,12 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c Thu Oct  1 13:46:48 2009
@@ -107,7 +107,9 @@
     }
 finally:
     x_free((void *)(m->filename));
-    x_free(m);
+    m->filename = NULL;
+    if (flags & ACR_IOH_CLEAR)
+        x_free(m);
     return rc;
 }
 
@@ -131,8 +133,10 @@
         if (m->base && shmdt(m->base) == -1) {
             rc = ACR_GET_OS_ERROR();
         }
+        m->filename = NULL;
     }
-    x_free(m);
+    if (flags & ACR_IOH_CLEAR)
+        x_free(m);
     return rc;
 }
 
@@ -144,7 +148,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EFTYPE;
     }
-    rc = acr_ioh_close(shm);
+    rc = acr_ioh_clear(shm);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }
@@ -523,6 +527,12 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c Thu Oct  1 13:46:48 2009
@@ -72,7 +72,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EFTYPE;
     }
-    rc = acr_ioh_close(dso);
+    rc = acr_ioh_clear(dso);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c Thu Oct  1 13:46:48 2009
@@ -41,7 +41,12 @@
             rc = ACR_SUCCESS;
     }
     x_free(fp->name);
-    x_free(fp);
+    fp->name = NULL;
+
+    if (flags & ACR_IOH_CLEAR)
+        x_free(fp);
+    else
+        fp->fd = -1;
     return rc;
 }
 
@@ -51,14 +56,20 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
-        case ACR_DESC_CLOSE:
+        case ACR_DESC_FINALIZE:
             if (dp->di > 0) {
                 acr_file_t *fp = ACR_IOH_FDATA(dp->di);
                 if (fp->flags & ACR_FOPEN_NOCLEANUP) {
-                    rc = file_cleanup(fp, ACR_DT_FILE, 0);
-                    ACR_IOH_FDATA(dp->di) = NULL;
+                    fp->fd = -1;
                 }
-                rc == 0 ? rc = acr_ioh_close(dp->di) : acr_ioh_close(dp->di);
+                rc = acr_ioh_clear(dp->di);
+            }
+            else
+                rc = ACR_EBADF;
+        break;
+        case ACR_DESC_CLOSE:
+            if (dp->di > 0) {
+                rc = acr_ioh_close(dp->di);
             }
             else
                 rc = ACR_EBADF;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c Thu Oct  1 13:46:48 2009
@@ -264,11 +264,29 @@
         rc = (*acr_ioh_tab[i].c)(acr_ioh_tab[i].h, acr_ioh_tab[i].type,
                                  acr_ioh_tab[i].flags);
     }
+
+    return rc;
+}
+
+int acr_ioh_clear(int i)
+{
+    int rc = 0;
+
+    if (i < 0 || i >= acr_ioh_mask)
+        return ACR_EBADF;
+    if (!__bitmap)
+        return ACR_ENOMEM;
+    if (IS_VALID_HANDLE(acr_ioh_tab[i].h) && acr_ioh_tab[i].c) {
+        /* Run the cleanup */
+        rc = (*acr_ioh_tab[i].c)(acr_ioh_tab[i].h, acr_ioh_tab[i].type,
+                                 acr_ioh_tab[i].flags | ACR_IOH_CLEAR);
+    }
     pthread_mutex_lock(&ios_lock);
     acr_ioh_tab[i] = nul_ioh_tab;
     __CLR_BIT(__bitmap, i);
 
     pthread_mutex_unlock(&ios_lock);
+
     return rc;
 }
 
@@ -303,6 +321,14 @@
     return rc;
 }
 
+ACR_DECLARE(int) ACR_IoClear(JNIEnv *_E, int dh)
+{
+    int rc = acr_ioh_clear(dh);
+
+    ACR_THROW_IO_IF_ERR(rc);
+    return rc;
+}
+
 #if defined(ACR_ENABLE_TEST)
 
 void acr_ioh_dump_stats()

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c Thu Oct  1 13:46:48 2009
@@ -70,14 +70,17 @@
     if (IS_VALID_MEMORY(m->base)) {
         if (munmap(m->base, m->size))
             rc = ACR_GET_OS_ERROR();
+        m->base = INVALID_MEMORY_VALUE;
     }
-    if (flags == MMAP_OWNS_FILE) {
+    if ((flags & MMAP_OWNS_FILE) && m->fd > 0) {
         /* Since we have opended the file close it.
          */
         if (close(m->fd))
             rc = ACR_GET_OS_ERROR();
+        m->fd = -1;
     }
-    x_free(m);
+    if (flags & ACR_IOH_CLEAR)
+        x_free(m);
     return rc;
 }
 
@@ -98,6 +101,12 @@
     int rc = ACR_SUCCESS;
 
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);
@@ -154,7 +163,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EFTYPE;
     }
-    rc = acr_ioh_close(map);
+    rc = acr_ioh_clear(map);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/mutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/mutex.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/mutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/mutex.c Thu Oct  1 13:46:48 2009
@@ -88,15 +88,19 @@
     if (type == ACR_DT_MUTEX) {
         int rc = 0;
         acr_pmutex_t *m = (acr_pmutex_t *)mutex;
-        if (m->filename[0])
+        if (m->filename[0]) {
             sem_unlink(m->filename);
+            m->filename[0] = '\0'
+        }
         if (m->sem != (sem_t *)SEM_FAILED) {
             if (sem_close(m->sem) < 0)
                 rc = ACR_GET_OS_ERROR();
+            m->sem = (sem_t *)SEM_FAILED;
         }
         else
             rc = ACR_EBADF;
-        x_free(m);
+        if (flags & ACR_IOH_CLEAR)
+            x_free(m);
         return rc;
     }
     return ACR_EFTYPE;
@@ -310,6 +314,7 @@
             }
             ick.val = 0;
             semctl(m->filedes, 0, IPC_RMID, ick);
+            m->filedes = -1;
             rc = ACR_SUCCESS;
         }
         if (m->filename) {
@@ -319,8 +324,10 @@
                     rc = ACR_GET_OS_ERROR();
             }
             x_free((void *)(m->filename));
+            m->filename = NULL;
         }
-        x_free(m);
+        if (flags & ACR_IOH_CLEAR)
+            x_free(m);
         return rc;
     }
     return ACR_EFTYPE;
@@ -342,9 +349,11 @@
                     rc = semop(m->filedes, &op, 1);
                 } while (rc < 0 && errno == EINTR);
             }
+            m->filedes = -1;
             rc = ACR_SUCCESS;
         }
-        x_free(m);
+        if (flags & ACR_IOH_CLEAR)
+            x_free(m);
         return rc;
     }
     return ACR_EFTYPE;
@@ -675,6 +684,12 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);
@@ -696,7 +711,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EFTYPE;
     }
-    rc = acr_ioh_close(mutex);
+    rc = acr_ioh_clear(mutex);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/sema.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/sema.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/sema.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/sema.c Thu Oct  1 13:46:48 2009
@@ -64,15 +64,19 @@
     if (type == ACR_DT_SEMAPHORE) {
         int rc = 0;
         acr_semaphore_t *s = (acr_semaphore_t *)sema;
-        if (s->name[0])
+        if (s->name[0]) {
             sem_unlink(s->name);
+            s->name[0] = '\0';
+        }
         if (s->sem != (sem_t *)SEM_FAILED) {
             if (sem_close(s->sem) < 0)
                 rc = ACR_GET_OS_ERROR();
+            s->sem = (sem_t *)SEM_FAILED;
         }
         else
             rc = ACR_EBADF;
-        x_free(s);
+        if (flags & ACR_IOH_CLEAR)
+            x_free(s);
         return rc;
     }
     return ACR_EFTYPE;
@@ -183,7 +187,7 @@
 
     /* Close will call the cleanup function
      */
-    return acr_ioh_close(sema);
+    return acr_ioh_clear(sema);
 }
 
 ACR_DECLARE(int) ACR_SemaphoreRemove(JNIEnv *_E, const acr_pchar_t *sname)
@@ -345,6 +349,12 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);
@@ -466,4 +476,3 @@
     }
     return ex == 0 ? JNI_TRUE : JNI_FALSE;
 }
-

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c Thu Oct  1 13:46:48 2009
@@ -84,6 +84,7 @@
         if (m->base && munmap(m->base, m->realsize) == -1) {
             rc = ACR_GET_OS_ERROR();
         }
+        m->base = NULL;
     }
     /* name-based shared memory */
     else {
@@ -106,7 +107,9 @@
     }
 finally:
     x_free((void *)(m->filename));
-    x_free(m);
+    m->filename = NULL;
+    if (flags & ACR_IOH_CLEAR)   
+        x_free(m);
     return rc;
 }
 
@@ -130,8 +133,10 @@
         if (m->base && shmdt(m->base) == -1) {
             rc = ACR_GET_OS_ERROR();
         }
+        m->filename = NULL;
     }
-    x_free(m);
+    if (flags & ACR_IOH_CLEAR)
+        x_free(m);
     return rc;
 }
 
@@ -143,7 +148,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EFTYPE;
     }
-    rc = acr_ioh_close(shm);
+    rc = acr_ioh_clear(shm);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }
@@ -503,6 +508,12 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c Thu Oct  1 13:46:48 2009
@@ -80,7 +80,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EFTYPE;
     }
-    rc = acr_ioh_close(dso);
+    rc = acr_ioh_clear(dso);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c Thu Oct  1 13:46:48 2009
@@ -43,7 +43,11 @@
             rc = ACR_SUCCESS;
     }
     x_free(fp->name);
-    x_free(fp);
+    fp->name = NULL;
+    if (flags & ACR_IOH_CLEAR)
+        x_free(fp);
+    else
+        fp->fd = INVALID_HANDLE_VALUE;
     return rc;
 }
 
@@ -53,14 +57,20 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
-        case ACR_DESC_CLOSE:
+        case ACR_DESC_FINALIZE:
             if (dp->di > 0) {
                 acr_file_t *fp = ACR_IOH_FDATA(dp->di);
                 if (fp->flags & ACR_FOPEN_NOCLEANUP) {
-                    rc = file_cleanup(fp, ACR_DT_FILE, 0);
-                    ACR_IOH_FDATA(dp->di) = NULL;
+                    fp->fd = INVALID_HANDLE_VALUE;
                 }
-                rc == 0 ? rc = acr_ioh_close(dp->di) : acr_ioh_close(dp->di);
+                rc = acr_ioh_clear(dp->di);
+            }
+            else
+                rc = ACR_EBADF;
+        break;
+        case ACR_DESC_CLOSE:
+            if (dp->di > 0) {
+                rc = acr_ioh_close(dp->di);
             }
             else
                 rc = ACR_EBADF;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c Thu Oct  1 13:46:48 2009
@@ -252,6 +252,23 @@
         rc = (*acr_ioh_tab[i].c)(acr_ioh_tab[i].h, acr_ioh_tab[i].type,
                                  acr_ioh_tab[i].flags);
     }
+
+    return rc;
+}
+
+int acr_ioh_clear(int i)
+{
+    int rc = 0;
+
+    if (i < 0 || i >= acr_ioh_mask)
+        return ACR_EBADF;
+    if (!__bitmap)
+        return ACR_ENOMEM;
+    if (IS_VALID_HANDLE(acr_ioh_tab[i].h) && acr_ioh_tab[i].c) {
+        /* Run the cleanup */
+        rc = (*acr_ioh_tab[i].c)(acr_ioh_tab[i].h, acr_ioh_tab[i].type,
+                                 acr_ioh_tab[i].flags | ACR_IOH_CLEAR);
+    }
     EnterCriticalSection(&ios_lock);
     acr_ioh_tab[i] = nul_ioh_tab;
     __CLR_BIT(__bitmap, i);
@@ -291,6 +308,14 @@
     return rc;
 }
 
+ACR_DECLARE(int) ACR_IoClear(JNIEnv *_E, int dh)
+{
+    int rc = acr_ioh_clear(dh);
+
+    ACR_THROW_IO_IF_ERR(rc);
+    return rc;
+}
+
 #if defined(ACR_ENABLE_TEST)
 
 void acr_ioh_dump_stats()

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c Thu Oct  1 13:46:48 2009
@@ -74,7 +74,8 @@
         if (!CloseHandle(m->fd))
             rc = ACR_GET_OS_ERROR();
     }
-    x_free(m);
+    if (flags & ACR_IOH_CLEAR)
+        x_free(m);
     return rc;
 }
 
@@ -95,6 +96,12 @@
     int rc = ACR_SUCCESS;
 
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);
@@ -135,7 +142,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EFTYPE;
     }
-    rc = acr_ioh_close(map);
+    rc = acr_ioh_clear(map);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c Thu Oct  1 13:46:48 2009
@@ -220,7 +220,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EINVAL;
     }
-    rc = acr_ioh_close(mutex);
+    rc = acr_ioh_clear(mutex);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }
@@ -247,6 +247,12 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c Thu Oct  1 13:46:48 2009
@@ -133,7 +133,7 @@
 
     /* Close will call the cleanup function
      */
-    return acr_ioh_close(sema);
+    return acr_ioh_clear(sema);
 }
 
 ACR_DECLARE(int) ACR_SemaphorePermSet(JNIEnv *_E, int sema, int perms,
@@ -167,7 +167,7 @@
 
     do {
         rc = 0;
-        ws = ACR_WaitForObjectOrSignal(s, INFINITE);        
+        ws = ACR_WaitForObjectOrSignal(s, INFINITE);
         switch (ws) {
             case WAIT_IO_COMPLETION:
             case WAIT_OBJECT_0:
@@ -292,6 +292,12 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c Thu Oct  1 13:46:48 2009
@@ -78,8 +78,12 @@
          */
         DeleteFileW(m->filename);
         x_free((void *)(m->filename));
+        m->filename = NULL;
     }
-    x_free(m);
+    m->memblk = NULL;
+    m->hmap   = NULL;
+    if (flags & ACR_IOH_CLEAR)
+        x_free(m);
     return rc;
 }
 
@@ -92,7 +96,7 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return ACR_EFTYPE;
     }
-    rc = acr_ioh_close(shm);
+    rc = acr_ioh_clear(shm);
     ACR_THROW_IO_IF_ERR(rc);
     return rc;
 }
@@ -405,6 +409,12 @@
 {
     int rc = ACR_SUCCESS;
     switch (cm) {
+        case ACR_DESC_FINALIZE:
+            if (dp->di > 0)
+                rc = acr_ioh_clear(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
         case ACR_DESC_CLOSE:
             if (dp->di > 0)
                 rc = acr_ioh_close(dp->di);

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=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Thu Oct  1 13:46:48
2009
@@ -95,6 +95,12 @@
     "Ljava/lang/Object;"
 };
 
+J_DECLARE_F_ID(0006) = {
+    NULL,
+    "ISVALID",
+    "I"
+};
+
 ACR_CLASS_LDEF(Descriptor)
 {
     int rv;
@@ -107,6 +113,7 @@
     J_LOAD_IFIELD(0003);
     J_LOAD_IFIELD(0004);
     J_LOAD_IFIELD(0005);
+    J_LOAD_IFIELD(0006);
     J_LOAD_METHOD(0000);
 
     return ACR_SUCCESS;
@@ -155,12 +162,10 @@
         cb.dp   = GET_IFIELD_V(0001, _O, void *);
         handler = GET_IFIELD_V(0002, _O, acr_descriptor_handler_fn_t *);
 
-        if (cb.di >= 0) {
-            SET_IFIELD_I(0000, _O, -1);
-        }
         if (cb.dp) {
             SET_IFIELD_P(0001, _O, NULL);
         }
+        SET_IFIELD_I(0006, _O, 0);
         if (handler) {
             int rc;
             cb.thiz = _O;
@@ -194,7 +199,7 @@
         if (handler) {
             cb.thiz = _O;
             cb.data = GET_IFIELD_O(0005, _O);
-            (*handler)(_E, _O, ACR_DESC_CLOSE, &cb);
+            (*handler)(_E, _O, ACR_DESC_FINALIZE, &cb);
         }
     }
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Thu Oct  1 13:46:48 2009
@@ -719,7 +719,7 @@
 
 ACR_JNI_EXPORT_DECLARE(int, TestPrivate, test053)(ACR_JNISTDARGS, jint d)
 {
-    return acr_ioh_close(d);
+    return acr_ioh_clear(d);
 }
 
 extern void acr_ioh_dump_stats();

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=820656&r1=820655&r2=820656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Thu
Oct  1 13:46:48 2009
@@ -620,8 +620,9 @@
         assertEquals("Result ", 2303, r);
         d.close();
         int c = test024(d);
-        // Second call must return -1
-        assertEquals("Result ", -1, c);
+        // Second call must return 2303
+        // because close doesn't clear the int
+        assertEquals("Result ", 2303, c);
 
         d = null;
         System.gc();
@@ -658,11 +659,6 @@
 		System.out.println("Long JNI   Call  : " + (e-p));
 		System.out.println("Result is        : " + r);
 
-        d.close();
-        int c = test024(d);
-        // Second call must return -1
-        assertEquals("Result ", -1, c);
-
         d = null;
         System.gc();
         // This should be enough for a gc
@@ -782,8 +778,8 @@
         assertEquals("Result ", 1964, n);
         d.close();
         int c = test024(d);
-        // Second call must return -1
-        assertEquals("Result ", -1, c);
+        // Second call must return 1964
+        assertEquals("Result ", 1964, c);
 
         d = null;
         System.gc();
@@ -820,11 +816,12 @@
         assertTrue("Equals other", d1.equals(d2));
         assertTrue("Equals self", d1.equals(d1));
         d1.close();
-        assertFalse("Equals closed", d1.equals(d2));
+        assertTrue("Equals closed", d1.equals(d2));
         d2.close();
         // They always match if both closed
         assertTrue("Both closed", d1.equals(d2));
         // If closed equals to NULL
+        d1.finalize();
         assertTrue("Not NULL", d1.equals(Descriptor.NULL));
 
         d1 = null;



Mime
View raw message