Author: mladen.turk(a)jboss.com
Date: 2007-10-01 04:17:46 -0400 (Mon, 01 Oct 2007)
New Revision: 1066
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/include/sight_types.h
trunk/sight/native/share/dir.c
trunk/sight/native/share/no.c
trunk/sight/native/share/proc.c
Log:
Add interrupt for recursive JNI calls
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/include/sight_local.h 2007-10-01 08:17:46 UTC (rev 1066)
@@ -375,11 +375,6 @@
#ifndef SIGHT_DO_STATS
#define SIGHT_DO_STATS 1
#endif
-#define SIGHT_IS_VALID_GLOBAL() apr_atomic_inc32(sight_global_atomic)
-#define SIGHT_GLOBAL_CLEANUP() apr_atomic_dec32(sight_global_atomic)
-#else /* !DEBUG */
-#define SIGHT_IS_VALID_GLOBAL() apr_atomic_inc32(sight_global_atomic)
-#define SIGHT_GLOBAL_CLEANUP() apr_atomic_dec32(sight_global_atomic)
#endif
#define SIGHT_GLOBAL_TRY if (apr_atomic_inc32(sight_global_atomic))
@@ -393,6 +388,7 @@
#define SIGHT_LOCAL_END(N) apr_atomic_dec32(&(N)->refcount); }
apr_atomic_dec32(sight_global_atomic)
#define SIGHT_LOCAL_BRK(N) apr_atomic_dec32(&(N)->refcount);
apr_atomic_dec32(sight_global_atomic)
+#define SIGHT_LOCAL_IRQ(N) apr_atomic_read32(&(N)->interrupted)
/* Statistics counters */
extern volatile apr_uint64_t sight_cnt_native_alloc;
Modified: trunk/sight/native/include/sight_types.h
===================================================================
--- trunk/sight/native/include/sight_types.h 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/include/sight_types.h 2007-10-01 08:17:46 UTC (rev 1066)
@@ -111,6 +111,7 @@
/* org.jboss.sight.NativeObject instance */
struct sight_object_t {
volatile apr_uint32_t refcount;
+ volatile apr_uint32_t interrupted;
apr_pool_t *pool;
void *native;
void *opaque;
Modified: trunk/sight/native/share/dir.c
===================================================================
--- trunk/sight/native/share/dir.c 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/share/dir.c 2007-10-01 08:17:46 UTC (rev 1066)
@@ -176,7 +176,7 @@
return rv;
}
-static apr_off_t calc_size_r(apr_dir_t *dir, const char *base, apr_pool_t *pool)
+static apr_off_t calc_size_r(sight_object_t *no, apr_dir_t *dir, const char *base,
apr_pool_t *pool)
{
apr_off_t nsize = 0;
@@ -204,25 +204,29 @@
continue;
subdir = apr_pstrcat(sp, base, "/", fi.name, NULL);
if (apr_dir_open(&sd, subdir, sp) == APR_SUCCESS)
- nsize += calc_size_r(sd, subdir, sp);
+ nsize += calc_size_r(no, sd, subdir, sp);
apr_pool_destroy(sp);
}
else {
nsize += fi.size;
}
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ return nsize;
+ }
+
} while (rc == APR_SUCCESS || APR_STATUS_IS_INCOMPLETE(rc));
return nsize;
}
-static apr_off_t calc_size_d(apr_dir_t *dir)
+static apr_off_t calc_size_d(sight_object_t *no)
{
apr_off_t nsize = 0;
apr_finfo_t fi;
apr_status_t rc;
-
+ apr_dir_t *dir = (apr_dir_t *)no->native;
do {
rc = apr_dir_read(&fi, APR_FINFO_SIZE | APR_FINFO_TYPE, dir);
if (rc == APR_SUCCESS) {
@@ -230,6 +234,9 @@
nsize += fi.size;
}
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ return nsize;
+ }
} while (rc == APR_SUCCESS || APR_STATUS_IS_INCOMPLETE(rc));
return nsize;
@@ -241,7 +248,6 @@
jstring path)
{
sight_object_t *no = J2P(instance, sight_object_t *);
- apr_dir_t *d;
apr_off_t len = 0;
SIGHT_ALLOC_CSTRING(path);
@@ -256,13 +262,11 @@
sight_strerror(SIGHT_ENOFILE));
goto cleanup;
}
- else
- d = (apr_dir_t *)no->native;
SIGHT_LOCAL_TRY(no) {
if (recursive)
- len = calc_size_r((apr_dir_t *)no->native, J2S(path), no->pool);
+ len = calc_size_r(no, (apr_dir_t *)no->native, J2S(path), no->pool);
else
- len = calc_size_d((apr_dir_t *)no->native);
+ len = calc_size_d(no);
} SIGHT_LOCAL_END(no);
cleanup:
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/share/no.c 2007-10-01 08:17:46 UTC (rev 1066)
@@ -259,6 +259,7 @@
SIGHT_GLOBAL_TRY {
refcount = apr_atomic_read32(&no->refcount);
while (refcount) {
+ apr_atomic_inc32(&no->interrupted);
apr_thread_yield();
refcount = apr_atomic_read32(&no->refcount);
}
Modified: trunk/sight/native/share/proc.c
===================================================================
--- trunk/sight/native/share/proc.c 2007-10-01 07:58:39 UTC (rev 1065)
+++ trunk/sight/native/share/proc.c 2007-10-01 08:17:46 UTC (rev 1066)
@@ -347,11 +347,27 @@
SIGHT_LOCAL_BRK(no);
return APR_EINVAL;
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_EINTR;
+ }
timeout_value = timeout * 1000L;
timeout_interval = timeout_value / 64;
do {
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
apr_sleep(timeout_interval);
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
APR_NOWAIT);
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
if (timeout_interval >= timeout_value)
break;
timeout_interval *= 2;
@@ -384,6 +400,10 @@
SIGHT_LOCAL_BRK(no);
return rc;
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_EINTR;
+ }
c = (*_E)->GetObjectClass(_E, progress);
cb.name = "progress";
cb.msig = "(I)I";
@@ -415,8 +435,20 @@
else if (cres > 0) {
timeout_interval = cres * 1000L;
}
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
apr_sleep(timeout_interval);
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
rc = apr_proc_wait(&p->p, &p->exitval, &p->exitwhy,
APR_NOWAIT);
+ if (SIGHT_LOCAL_IRQ(no)) {
+ rc = APR_EINTR;
+ break;
+ }
if (timeout > 0) {
if (timeout_interval >= timeout_value)
break;