Author: mladen.turk(a)jboss.com
Date: 2007-10-03 12:58:16 -0400 (Wed, 03 Oct 2007)
New Revision: 1082
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/include/sight_types.h
trunk/sight/native/share/library.c
trunk/sight/native/share/no.c
Log:
Add atomics option as compile time defined
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-10-03 16:47:41 UTC (rev 1081)
+++ trunk/sight/native/include/sight_local.h 2007-10-03 16:58:16 UTC (rev 1082)
@@ -377,9 +377,6 @@
#endif
#endif
-/* For now use APR reference counters */
-#define SIGHT_APR_REFCOUNT 1
-
#if SIGHT_APR_REFCOUNT
#define SIGHT_GLOBAL_TRY if (apr_atomic_inc32(sight_global_atomic))
#define SIGHT_GLOBAL_END() apr_atomic_dec32(sight_global_atomic)
Modified: trunk/sight/native/include/sight_types.h
===================================================================
--- trunk/sight/native/include/sight_types.h 2007-10-03 16:47:41 UTC (rev 1081)
+++ trunk/sight/native/include/sight_types.h 2007-10-03 16:58:16 UTC (rev 1082)
@@ -59,6 +59,9 @@
#define SIGHT_MAX_PROCESSES 65536
+/* For now use APR reference counters */
+#define SIGHT_APR_REFCOUNT 1
+
typedef struct JAVA_C_ID {
jclass i;
jclass a;
@@ -110,8 +113,10 @@
/* org.jboss.sight.NativeObject instance */
struct sight_object_t {
+#if SIGHT_APR_REFCOUNT
volatile apr_uint32_t refcount;
volatile apr_uint32_t interrupted;
+#endif
apr_pool_t *pool;
void *native;
void *opaque;
Modified: trunk/sight/native/share/library.c
===================================================================
--- trunk/sight/native/share/library.c 2007-10-03 16:47:41 UTC (rev 1081)
+++ trunk/sight/native/share/library.c 2007-10-03 16:58:16 UTC (rev 1082)
@@ -233,16 +233,19 @@
SIGHT_EXPORT_DECLARE(void, Library, terminate0)(SIGHT_STDARGS)
{
- apr_uint32_t ioc = 0;
UNREFERENCED_STDARGS;
/* TODO Add reference count */
if (sight_global_pool) {
+#if SIGHT_APR_REFCOUNT
+ apr_uint32_t ioc = 0;
apr_uint32_t in_object_count = apr_atomic_dec32(sight_global_atomic);
+#endif
#ifdef SIGHT_DO_STATS
fprintf(stderr, "\nLibrary terminate ............\n");
fprintf(stderr, "Global Atomic counter : %d\n", sight_global_a);
#endif
+#if SIGHT_APR_REFCOUNT
while (in_object_count) {
apr_thread_yield();
in_object_count = apr_atomic_read32(sight_global_atomic);
@@ -262,6 +265,7 @@
#endif
}
}
+#endif
apr_pool_destroy(sight_temp_pool);
apr_pool_destroy(sight_global_pool);
sight_temp_pool = NULL;
@@ -328,19 +332,43 @@
SIGHT_EXPORT_DECLARE(void, Library, clear0)(SIGHT_STDARGS)
{
- UNREFERENCED_STDARGS;
+ UNREFERENCED_O;
+
if (sight_global_pool) {
+#if SIGHT_APR_REFCOUNT
+ apr_uint32_t ioc = 0;
apr_uint32_t in_object_count = apr_atomic_dec32(sight_global_atomic);
+#endif
/* Wait untill all object native calls are finished */
#ifdef SIGHT_DO_STATS
fprintf(stderr, "\nLibrary clear ................\n");
fprintf(stderr, "Global Atomic counter : %d\n", sight_global_a);
#endif
+#if SIGHT_APR_REFCOUNT
while (in_object_count) {
apr_thread_yield();
in_object_count = apr_atomic_read32(sight_global_atomic);
}
+ if (ioc++ > OPTIMISTIC_LOCK_CNT) {
+ /* Sleep one millisecond */
+ apr_sleep(1000L);
+ }
+ if (ioc > OPTIMISTIC_LOCK_MAX) {
+ /* TODO: We have a zombie or a lengthy JNI op.
+ * Find a way to bail out without crushing JVM
+ */
+#ifdef SIGHT_DO_STATS
+ fprintf(stderr, "Library.clear0() call is locked ...\n");
+ fprintf(stderr, "Bailing out !\n");
+ fflush(stderr);
+#endif
+ throwAprException(_E, APR_TIMEUP);
+ return;
+ }
+
+#endif
+
apr_pool_clear(sight_global_pool);
apr_atomic_set32(sight_global_atomic, 1);
}
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-03 16:47:41 UTC (rev 1081)
+++ trunk/sight/native/share/no.c 2007-10-03 16:58:16 UTC (rev 1082)
@@ -199,7 +199,9 @@
{
sight_object_t *no = J2P(instance, sight_object_t *);
jobject object = NULL;
+#if SIGHT_APR_REFCOUNT
apr_uint32_t refcount;
+#endif
UNREFERENCED_O;
@@ -214,11 +216,13 @@
(*_E)->DeleteWeakGlobalRef(_E, no->object);
no->object = object;
}
+#if SIGHT_APR_REFCOUNT
refcount = apr_atomic_read32(&no->refcount);
while (refcount) {
apr_thread_yield();
refcount = apr_atomic_read32(&no->refcount);
}
+#endif
if (no->pool)
apr_pool_cleanup_kill(no->pool, no, native_object_cleanup);
if (no->object) {
@@ -244,8 +248,9 @@
jlong instance)
{
sight_object_t *no = J2P(instance, sight_object_t *);
+#if SIGHT_APR_REFCOUNT
apr_uint32_t refcount;
-
+#endif
UNREFERENCED_O;
#ifdef SIGHT_DO_STATS
@@ -254,13 +259,14 @@
if (!no)
return;
SIGHT_GLOBAL_TRY {
+#if SIGHT_APR_REFCOUNT
refcount = apr_atomic_read32(&no->refcount);
while (refcount) {
apr_atomic_inc32(&no->interrupted);
apr_thread_yield();
refcount = apr_atomic_read32(&no->refcount);
}
-
+#endif
if (no->pool)
apr_pool_cleanup_kill(no->pool, no, native_object_cleanup);
if (no->clean)