commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r805865 - in /commons/sandbox/runtime/trunk/src: main/native/include/acr_semaphore.h main/native/os/unix/psema.c main/native/os/win32/psema.c main/native/test/testcase.c test/org/apache/commons/runtime/TestSemaphore.java
Date Wed, 19 Aug 2009 16:18:38 GMT
Author: mturk
Date: Wed Aug 19 16:18:37 2009
New Revision: 805865

URL: http://svn.apache.org/viewvc?rev=805865&view=rev
Log:
Add SemaphoreRemove API call

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_semaphore.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_semaphore.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_semaphore.h?rev=805865&r1=805864&r2=805865&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_semaphore.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_semaphore.h Wed Aug 19 16:18:37
2009
@@ -87,6 +87,16 @@
  */
 ACR_DECLARE(int) ACR_SemaphoreClose(JNIEnv *env, int semaphore);
 
+/**
+ * Remove the given semaphore.
+ * @param env JNI environment to use.
+ * @param name A name of the semaphore to open.
+ * @note This call has no effect on some platforms, but should be called
+ *       before create call if there is unlinked semaphore left by the
+ *       same name.
+ */
+ACR_DECLARE(int) ACR_SemaphoreRemove(JNIEnv *env, const acr_pchar_t *name);
+
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c?rev=805865&r1=805864&r2=805865&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c Wed Aug 19 16:18:37 2009
@@ -31,6 +31,10 @@
 #define SEM_FAILED (-1)
 #endif
 
+#ifndef NAME_MAX
+#define NAME_MAX   (64)
+#endif
+
 J_DECLARE_CLAZZ = {
     NULL,
     NULL,
@@ -48,7 +52,7 @@
 struct acr_semaphore_t {
     sem_t *sem;
     int    locked;
-    char   name[64];
+    char   name[NAME_MAX];
 };
 
 static int semaphore_cleanup(void *sema, int type, unsigned int flags)
@@ -84,7 +88,7 @@
     else {
         if (*name != '/')
             s->name[0] = '/';
-        strlcat(s->name, name, 62);
+        strlcat(s->name, name, NAME_MAX - 2);
     }
     do {
         s->sem = sem_open(s->name, O_CREAT | O_EXCL, 0644, value);
@@ -147,7 +151,7 @@
         return -1;
     if (*name != '/')
         s->name[0] = '/';
-    strlcat(s->name, name, 62);
+    strlcat(s->name, name, NAME_MAX -2);
     s->sem = sem_open(s->name, O_RDWR);
     if (s->sem == (sem_t *)SEM_FAILED) {
         rc = ACR_GET_OS_ERROR();
@@ -181,6 +185,19 @@
     return acr_ioh_close(sema);
 }
 
+ACR_DECLARE(int) ACR_SemaphoreRemove(JNIEnv *_E, const acr_pchar_t *sname)
+{
+    char name[NAME_MAX] = "";
+    if (!sname) {
+        return ACR_EINVAL;
+    }
+    if (*sname != '/')
+        name[0] = '/';
+    strlcat(name, sname, NAME_MAX -2);
+
+    return sem_unlink(name);
+}
+
 ACR_DECLARE(int) ACR_SemaphorePermSet(JNIEnv *_E, int sema, int perms,
                                       acr_uid_t uid, acr_uid_t gid)
 {

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c?rev=805865&r1=805864&r2=805865&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c Wed Aug 19 16:18:37 2009
@@ -230,6 +230,12 @@
 
 }
 
+ACR_DECLARE(int) ACR_SemaphoreRemove(JNIEnv *_E, const wchar_t *name)
+{
+    /* No op on windows */
+    return ACR_SUCCESS;
+}
+
 ACR_CLASS_LDEF(Semaphore)
 {
     int rv;

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=805865&r1=805864&r2=805865&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Wed Aug 19 16:18:37 2009
@@ -805,3 +805,8 @@
     return ACR_SemaphoreRelease(_E, s);
 }
 
+ACR_JNI_EXPORT_DECLARE(jint, TestSemaphore, test006)(ACR_JNISTDARGS, jint s)
+{
+    return ACR_SemaphoreRemove(_E, sem_name);
+}
+

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java?rev=805865&r1=805864&r2=805865&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java Wed
Aug 19 16:18:37 2009
@@ -31,6 +31,7 @@
     private static native int      test003(int v);  // Close
     private static native int      test004(int v);  // Wait
     private static native int      test005(int v);  // Release
+    private static native int      test006(int v);  // Remove
 
     public static Test suite() {
         TestSuite suite = new TestSuite(TestSemaphore.class);
@@ -55,6 +56,19 @@
             // Ignore
         }
         if (s < 0) {
+            try {
+                s = test001(0);
+            } catch (Throwable t) {
+                // Ignore
+            }
+            if (s > 0) {
+                owner = true;
+            }
+        }
+        if (s < 0) {
+            // Neither Create or Attach were sussesful
+            // Remove and try Create again
+            test006(0);
             s = test001(0);
             if (s > 0) {
                 owner = true;



Mime
View raw message