You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/08 19:00:44 UTC
svn commit: r763315 - in /commons/sandbox/runtime/trunk/src/main/native:
include/acr_version.h include/acr_vm.h os/unix/main.c
Author: mturk
Date: Wed Apr 8 17:00:43 2009
New Revision: 763315
URL: http://svn.apache.org/viewvc?rev=763315&view=rev
Log:
Use thread private storage for obtaining the JNIEnv
Added:
commons/sandbox/runtime/trunk/src/main/native/include/acr_vm.h (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr_version.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_version.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_version.h?rev=763315&r1=763314&r2=763315&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_version.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_version.h Wed Apr 8 17:00:43 2009
@@ -67,20 +67,17 @@
*/
#undef ACR_IS_DEV_VERSION
-/* ACR_STRINGIFY is defined here, and also in apr_general.h, so wrap it */
-#ifndef ACR_STRINGIFY
/** Properly quote a value as a string in the C preprocessor */
#define ACR_STRINGIFY(n) ACR_STRINGIFY_HELPER(n)
-/** Helper macro for APR_STRINGIFY */
+/** Helper macro for ACR_STRINGIFY */
#define ACR_STRINGIFY_HELPER(n) #n
-#endif
/** The formatted string of APU's version */
#define ACR_VERSION_STRING \
- ACR_STRINGIFY(ACR_MAJOR_VERSION) "."\
- ACR_STRINGIFY(ACR_MINOR_VERSION) "."\
- ACR_STRINGIFY(ACR_PATCH_VERSION)\
+ ACR_STRINGIFY(ACR_MAJOR_VERSION) "." \
+ ACR_STRINGIFY(ACR_MINOR_VERSION) "." \
+ ACR_STRINGIFY(ACR_PATCH_VERSION) \
ACR_IS_DEV_STRING
/** Internal: string form of the "is dev" flag */
@@ -90,6 +87,12 @@
#define ACR_IS_DEV_STRING ""
#endif
+/** Macro for Win32 .rc files using numeric csv representation */
+#define ACR_VERSION_STRING_CSV ACR_MAJOR_VERSION ##, \
+ ##ACR_MINOR_VERSION ##, \
+ ##ACR_PATCH_VERSION
+
+
#ifdef __cplusplus
}
#endif
Added: commons/sandbox/runtime/trunk/src/main/native/include/acr_vm.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_vm.h?rev=763315&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_vm.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_vm.h Wed Apr 8 17:00:43 2009
@@ -0,0 +1,48 @@
+/* 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.
+ */
+
+#ifndef _ACR_VM_H
+#define _ACR_VM_H
+
+#include "acr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_vm.h
+ * @brief
+ *
+ * ACR JVM functions
+ *
+ */
+
+/*
+ * Get current thread JNI Environment
+ * @remark The function will attach to the
+ * current JVM thread. This function must be called to obtain the JNIEnv
+ * for callback methods that can execute in a different thread
+ * from the one used for initialisation.
+ */
+ACR_DECLARE(JNIEnv *)ACR_GetJNIEnv(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_VM_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr_vm.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c?rev=763315&r1=763314&r2=763315&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c Wed Apr 8 17:00:43 2009
@@ -16,6 +16,7 @@
#include "acr.h"
#include "acr_private.h"
+#include "acr_vm.h"
#include <pthread.h>
@@ -62,6 +63,32 @@
}
env = epp;
-
return JNI_VERSION_1_4;
}
+
+ACR_DECLARE(JNIEnv *)ACR_GetJNIEnv()
+{
+ acr_thread_local_t *tlsd;
+ void *epp = NULL;
+
+ if (acr_pvm == NULL) {
+ return NULL;
+ }
+ tlsd = (acr_thread_local_t *)pthread_getspecific(acr_thread_key);
+ if (tlsd == NULL) {
+ tlsd = (acr_thread_local_t *)malloc(sizeof(acr_thread_local_t));
+ if (tlsd == NULL)
+ return NULL;
+ if ((*acr_pvm)->GetEnv(acr_pvm, (void **)&epp,
+ JNI_VERSION_1_4) == JNI_EDETACHED) {
+ (*acr_pvm)->AttachCurrentThread(acr_pvm, (void **)&epp, NULL);
+ tlsd->attached = 1;
+ }
+ else
+ tlsd->attached = 0;
+ tlsd->env = epp;
+ pthread_setspecific(acr_thread_key, tlsd);
+ }
+
+ return tlsd->env;
+}