commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r806268 - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.in Makefile.msc.in include/acr_procmutex.h os/darwin/pmutex.c os/unix/pmutex.c os/win32/pmutex.c shared/mutex.c shared/sema.c
Date Thu, 20 Aug 2009 17:28:30 GMT
Author: mturk
Date: Thu Aug 20 17:28:29 2009
New Revision: 806268

URL: http://svn.apache.org/viewvc?rev=806268&view=rev
Log:
Initial Mutex Java API

Added:
    commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr_procmutex.h
    commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c
    commons/sandbox/runtime/trunk/src/main/native/shared/sema.c

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=806268&r1=806267&r2=806268&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Thu Aug 20 17:28:29 2009
@@ -88,6 +88,7 @@
 	$(SRCDIR)/shared/mbstr.$(OBJ) \
 	$(SRCDIR)/shared/memory.$(OBJ) \
 	$(SRCDIR)/shared/modules.$(OBJ) \
+	$(SRCDIR)/shared/mutex.$(OBJ) \
 	$(SRCDIR)/shared/native.$(OBJ) \
 	$(SRCDIR)/shared/nbb.$(OBJ) \
 	$(SRCDIR)/shared/pointer.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=806268&r1=806267&r2=806268&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Thu Aug 20 17:28:29 2009
@@ -79,6 +79,7 @@
 	$(SRCDIR)/shared/mbstr.$(OBJ) \
 	$(SRCDIR)/shared/memory.$(OBJ) \
 	$(SRCDIR)/shared/modules.$(OBJ) \
+	$(SRCDIR)/shared/mutex.$(OBJ) \
 	$(SRCDIR)/shared/native.$(OBJ) \
 	$(SRCDIR)/shared/nbb.$(OBJ) \
 	$(SRCDIR)/shared/pointer.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_procmutex.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_procmutex.h?rev=806268&r1=806267&r2=806268&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_procmutex.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_procmutex.h Thu Aug 20 17:28:29
2009
@@ -100,6 +100,28 @@
  */
 ACR_DECLARE(int) ACR_ProcMutexClose(JNIEnv *env, int mutex);
 
+/**
+ * Create and initialize a mutex that can be used to synchronize processes.
+ * @param env JNI environment to use.
+ * @param fname A file name to use if the lock mechanism requires one.  This
+ *        argument should always be provided.  The lock code itself will
+ *        determine if it should be used.
+ */
+ACR_DECLARE(jobject) ACR_ProcMutexObjectCreate(JNIEnv *env,
+                                               const acr_pchar_t *fname);
+
+/**
+ * Re-open a mutex in child process.
+ * @param env JNI environment to use.
+ * @param fname A file name to use if the lock mechanism requires one.  This
+ *        argument should always be provided.  The lock code itself will
+ *        determine if it should be used.
+ * @remark This function must be called to maintain portability, even
+ *         if the underlying lock mechanism does not require it.
+ */
+ACR_DECLARE(jobject) ACR_ProcMutexObjectAttach(JNIEnv *env,
+                                               const acr_pchar_t *fname);
+
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c?rev=806268&r1=806267&r2=806268&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c Thu Aug 20 17:28:29 2009
@@ -249,3 +249,96 @@
     ACR_UnloadClass(_E, &_clazzn);
 }
 
+static int mtx_descriptor_cleanup(ACR_JNISTDARGS,
+                                  acr_descriptor_cb_type_e cm,
+                                  acr_descriptor_cb_t *dp)
+{
+    int rc = ACR_SUCCESS;
+    switch (cm) {
+        case ACR_DESC_CLOSE:
+            if (dp->di > 0)
+                rc = acr_ioh_close(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
+        default:
+            rc = ACR_ENOTIMPL;
+        break;
+    }
+    return rc;
+}
+
+ACR_DECLARE(jobject) ACR_ProcMutexObjectCreate(JNIEnv *_E,
+                                               const acr_pchar_t *name)
+{
+    jobject mtxo;
+    jobject mtxd;
+    int     imtx;
+
+    imtx = ACR_ProcMutexCreate(_E, name);
+    if (imtx < 0) {
+
+        return NULL;
+    }
+    /* Create Descriptor Object */
+    mtxd = ACR_DescriptorCreate(_E, ACR_DT_MUTEX, imtx, NULL,
+                                mtx_descriptor_cleanup);
+    if (!mtxd) {
+
+        return NULL;
+    }
+    mtxo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mtxd);
+    return mtxo;
+}
+
+ACR_DECLARE(jobject) ACR_ProcMutexObjectAttach(JNIEnv *_E,
+                                               const acr_pchar_t *name)
+{
+    jobject mtxo;
+    jobject mtxd;
+    int     imtx;
+
+    imtx = ACR_ProcMutexAttach(_E, name);
+    if (imtx < 0) {
+
+        return NULL;
+    }
+    /* Create Descriptor Object */
+    mtxd = ACR_DescriptorCreate(_E, ACR_DT_MUTEX, imtx, NULL,
+                                mtx_descriptor_cleanup);
+    if (!mtxd) {
+
+        return NULL;
+    }
+    mtxo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mtxd);
+    return mtxo;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, Mutex, create1)(ACR_JNISTDARGS,
+                                                jstring name)
+{
+
+    jobject mtxo = NULL;
+    UNREFERENCED_O;
+
+    WITH_CSTR(name) {
+        mtxo = ACR_ProcMutexObjectCreate(_E, J2S(name));
+    } END_WITH_CSTR(name);
+
+    return mtxo;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, Mutex, create2)(ACR_JNISTDARGS,
+                                                jstring name)
+{
+
+    jobject mtxo = NULL;
+    UNREFERENCED_O;
+
+    WITH_CSTR(name) {
+        mtxo = ACR_ProcMutexObjectAttach(_E, J2S(name));
+    } END_WITH_CSTR(name);
+
+    return mtxo;
+}
+

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c?rev=806268&r1=806267&r2=806268&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c Thu Aug 20 17:28:29 2009
@@ -236,3 +236,96 @@
     ACR_UnloadClass(_E, &_clazzn);
 }
 
+static int mtx_descriptor_cleanup(ACR_JNISTDARGS,
+                                  acr_descriptor_cb_type_e cm,
+                                  acr_descriptor_cb_t *dp)
+{
+    int rc = ACR_SUCCESS;
+    switch (cm) {
+        case ACR_DESC_CLOSE:
+            if (dp->di > 0)
+                rc = acr_ioh_close(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
+        default:
+            rc = ACR_ENOTIMPL;
+        break;
+    }
+    return rc;
+}
+
+ACR_DECLARE(jobject) ACR_ProcMutexObjectCreate(JNIEnv *_E,
+                                               const acr_pchar_t *name)
+{
+    jobject mtxo;
+    jobject mtxd;
+    int     imtx;
+
+    imtx = ACR_ProcMutexCreate(_E, name);
+    if (imtx < 0) {
+
+        return NULL;
+    }
+    /* Create Descriptor Object */
+    mtxd = ACR_DescriptorCreate(_E, ACR_DT_MUTEX, imtx, NULL,
+                                mtx_descriptor_cleanup);
+    if (!mtxd) {
+
+        return NULL;
+    }
+    mtxo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mtxd);
+    return mtxo;
+}
+
+ACR_DECLARE(jobject) ACR_ProcMutexObjectAttach(JNIEnv *_E,
+                                               const acr_pchar_t *name)
+{
+    jobject mtxo;
+    jobject mtxd;
+    int     imtx;
+
+    imtx = ACR_ProcMutexAttach(_E, name);
+    if (imtx < 0) {
+
+        return NULL;
+    }
+    /* Create Descriptor Object */
+    mtxd = ACR_DescriptorCreate(_E, ACR_DT_MUTEX, imtx, NULL,
+                                mtx_descriptor_cleanup);
+    if (!mtxd) {
+
+        return NULL;
+    }
+    mtxo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mtxd);
+    return mtxo;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, Mutex, create1)(ACR_JNISTDARGS,
+                                                jstring name)
+{
+
+    jobject mtxo = NULL;
+    UNREFERENCED_O;
+
+    WITH_CSTR(name) {
+        mtxo = ACR_ProcMutexObjectCreate(_E, J2S(name));
+    } END_WITH_CSTR(name);
+
+    return mtxo;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, Mutex, create2)(ACR_JNISTDARGS,
+                                                jstring name)
+{
+
+    jobject mtxo = NULL;
+    UNREFERENCED_O;
+
+    WITH_CSTR(name) {
+        mtxo = ACR_ProcMutexObjectAttach(_E, J2S(name));
+    } END_WITH_CSTR(name);
+
+    return mtxo;
+}
+

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c?rev=806268&r1=806267&r2=806268&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c Thu Aug 20 17:28:29 2009
@@ -216,3 +216,96 @@
     ACR_UnloadClass(_E, &_clazzn);
 }
 
+static int mtx_descriptor_cleanup(ACR_JNISTDARGS,
+                                  acr_descriptor_cb_type_e cm,
+                                  acr_descriptor_cb_t *dp)
+{
+    int rc = ACR_SUCCESS;
+    switch (cm) {
+        case ACR_DESC_CLOSE:
+            if (dp->di > 0)
+                rc = acr_ioh_close(dp->di);
+            else
+                rc = ACR_EBADF;
+        break;
+        default:
+            rc = ACR_ENOTIMPL;
+        break;
+    }
+    return rc;
+}
+
+ACR_DECLARE(jobject) ACR_ProcMutexObjectCreate(JNIEnv *_E,
+                                               const acr_pchar_t *name)
+{
+    jobject mtxo;
+    jobject mtxd;
+    int     imtx;
+
+    imtx = ACR_ProcMutexCreate(_E, name);
+    if (imtx < 0) {
+
+        return NULL;
+    }
+    /* Create Descriptor Object */
+    mtxd = ACR_DescriptorCreate(_E, ACR_DT_MUTEX, imtx, NULL,
+                                mtx_descriptor_cleanup);
+    if (!mtxd) {
+
+        return NULL;
+    }
+    mtxo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mtxd);
+    return mtxo;
+}
+
+ACR_DECLARE(jobject) ACR_ProcMutexObjectAttach(JNIEnv *_E,
+                                               const acr_pchar_t *name)
+{
+    jobject mtxo;
+    jobject mtxd;
+    int     imtx;
+
+    imtx = ACR_ProcMutexAttach(_E, name);
+    if (imtx < 0) {
+
+        return NULL;
+    }
+    /* Create Descriptor Object */
+    mtxd = ACR_DescriptorCreate(_E, ACR_DT_MUTEX, imtx, NULL,
+                                mtx_descriptor_cleanup);
+    if (!mtxd) {
+
+        return NULL;
+    }
+    mtxo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mtxd);
+    return mtxo;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, Mutex, create1)(ACR_JNISTDARGS,
+                                                jstring name)
+{
+
+    jobject mtxo = NULL;
+    UNREFERENCED_O;
+
+    WITH_WSTR(name) {
+        mtxo = ACR_ProcMutexObjectCreate(_E, J2W(name));
+    } END_WITH_WSTR(name);
+
+    return mtxo;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, Mutex, create2)(ACR_JNISTDARGS,
+                                                jstring name)
+{
+
+    jobject mtxo = NULL;
+    UNREFERENCED_O;
+
+    WITH_WSTR(name) {
+        mtxo = ACR_ProcMutexObjectAttach(_E, J2W(name));
+    } END_WITH_WSTR(name);
+
+    return mtxo;
+}
+

Added: commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c?rev=806268&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c Thu Aug 20 17:28:29 2009
@@ -0,0 +1,91 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_clazz.h"
+#include "acr_error.h"
+#include "acr_memory.h"
+#include "acr_string.h"
+#include "acr_descriptor.h"
+#include "acr_procmutex.h"
+
+ACR_JNI_EXPORT_DECLARE(jobject, Mutex, create0)(ACR_JNISTDARGS,
+                                                jint value)
+{
+
+    jobject mtxo = NULL;
+    UNREFERENCED_O;
+
+    mtxo = ACR_ProcMutexObjectCreate(_E, NULL);
+    return mtxo;
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Mutex, lock0)(ACR_JNISTDARGS,
+                                           jobject mtxd)
+{
+    int rc = ACR_EBADF;
+    int md;
+    UNREFERENCED_O;
+
+    md = ACR_DescriptorGetInt(_E, mtxd);
+    if (md > 0) {
+        rc = ACR_ProcMutexLock(_E, md);
+    }
+    if (rc != ACR_SUCCESS) {
+        if (!ACR_STATUS_IS_EBUSY(rc)) {
+            ACR_THROW_IO_IF_ERR(rc);
+        }
+    }
+}
+
+ACR_JNI_EXPORT_DECLARE(jboolean, Mutex, lock1)(ACR_JNISTDARGS,
+                                               jobject mtxd)
+{
+    int rc = ACR_EBADF;
+    int md;
+    UNREFERENCED_O;
+
+    md = ACR_DescriptorGetInt(_E, mtxd);
+    if (md > 0) {
+        rc = ACR_ProcMutexTryLock(_E, md);
+    }
+    if (rc != ACR_SUCCESS) {
+        if (!ACR_STATUS_IS_EBUSY(rc)) {
+            ACR_THROW_IO_IF_ERR(rc);
+        }
+        return JNI_FALSE;
+    }
+    else
+        return JNI_FALSE;
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Mutex, release0)(ACR_JNISTDARGS,
+                                              jobject mtxd)
+{
+    int rc = ACR_EBADF;
+    int md;
+    UNREFERENCED_O;
+
+    md = ACR_DescriptorGetInt(_E, mtxd);
+    if (md > 0) {
+        rc = ACR_ProcMutexRelease(_E, md);
+    }
+
+    ACR_THROW_IO_IF_ERR(rc);
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/sema.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/sema.c?rev=806268&r1=806267&r2=806268&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/sema.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/sema.c Thu Aug 20 17:28:29 2009
@@ -22,7 +22,6 @@
 #include "acr_memory.h"
 #include "acr_string.h"
 #include "acr_descriptor.h"
-#include "acr_pointer.h"
 #include "acr_semaphore.h"
 
 ACR_JNI_EXPORT_DECLARE(jobject, Semaphore, create0)(ACR_JNISTDARGS,



Mime
View raw message