Author: mladen.turk(a)jboss.com
Date: 2007-10-06 04:32:13 -0400 (Sat, 06 Oct 2007)
New Revision: 1086
Modified:
trunk/sight/native/configure.in
trunk/sight/native/os/linux/process.c
trunk/sight/native/share/no.c
Log:
Make term more robust. This is actually from Apache Httpd
Modified: trunk/sight/native/configure.in
===================================================================
--- trunk/sight/native/configure.in 2007-10-04 06:24:12 UTC (rev 1085)
+++ trunk/sight/native/configure.in 2007-10-06 08:32:13 UTC (rev 1086)
@@ -264,7 +264,7 @@
AC_CHECK_HEADERS([netinet/tcp.h])
dnl ----------------------------- Checking for missing POSIX thread functions
-AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
+AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r getpgid])
if test -d $srcdir/test; then
Modified: trunk/sight/native/os/linux/process.c
===================================================================
--- trunk/sight/native/os/linux/process.c 2007-10-04 06:24:12 UTC (rev 1085)
+++ trunk/sight/native/os/linux/process.c 2007-10-06 08:32:13 UTC (rev 1086)
@@ -554,13 +554,46 @@
SIGHT_EXPORT_DECLARE(jint, Process, term0)(SIGHT_STDARGS, jint pid,
jint signum)
{
- jint rv = APR_SUCCESS;
+#ifndef HAVE_GETPGID
+ apr_proc_t proc;
+ apr_status_t rv;
+ apr_exit_why_e why;
+ int status;
- if (kill(pid, signum) == -1) {
+ /* Ensure pid sanity */
+ if (pid < 1) {
+ return APR_EINVAL;
+ }
+
+ proc.pid = pid;
+ rv = apr_proc_wait(&proc, &status, &why, APR_NOWAIT);
+ if (rv == APR_CHILD_DONE) {
+ /* Process already dead... */
+ return APR_EINVAL;
+ }
+ else if (rv != APR_CHILD_NOTDONE) {
+ return rv;
+ }
+#else
+ pid_t pg;
+
+ /* Ensure pid sanity. */
+ if (pid < 1) {
+ return APR_EINVAL;
+ }
+
+ pg = getpgid(pid);
+ if (pg == -1) {
+ /* Process already dead... */
return apr_get_os_error();
}
+#endif
+
+ if (kill(pid, signum)) {
+ return apr_get_os_error();
+ }
else
- return rv;
+ return APR_SUCCESS;
}
SIGHT_EXPORT_DECLARE(jint, Process, signal0)(SIGHT_STDARGS, jint pid,
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-04 06:24:12 UTC (rev 1085)
+++ trunk/sight/native/share/no.c 2007-10-06 08:32:13 UTC (rev 1086)
@@ -194,12 +194,16 @@
} SIGHT_LOCAL_END(no);
}
+#define OPTIMISTIC_LOCK_CNT 10000
+#define OPTIMISTIC_LOCK_MAX OPTIMISTIC_LOCK_CNT + 60000
+
SIGHT_EXPORT_DECLARE(void, NativeObject, free0)(SIGHT_STDARGS,
jlong instance)
{
sight_object_t *no = J2P(instance, sight_object_t *);
jobject object = NULL;
#if SIGHT_APR_REFCOUNT
+ apr_uint32_t ioc = 0;
apr_uint32_t refcount;
#endif
@@ -222,6 +226,21 @@
while (refcount) {
apr_thread_yield();
refcount = apr_atomic_read32(&no->refcount);
+ 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, "Native.object() call is locked ...\n");
+ fprintf(stderr, "Bailing out !\n");
+ fflush(stderr);
+ exit(-1);
+#endif
+ }
}
#endif
if (no->pool)
@@ -250,6 +269,7 @@
{
sight_object_t *no = J2P(instance, sight_object_t *);
#if SIGHT_APR_REFCOUNT
+ apr_uint32_t ioc = 0;
apr_uint32_t refcount;
#endif
UNREFERENCED_O;
@@ -266,6 +286,22 @@
while (refcount) {
apr_thread_yield();
refcount = apr_atomic_read32(&no->refcount);
+ 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, "NativeObject.clear() call is locked ...\n");
+ fprintf(stderr, "Bailing out !\n");
+ fflush(stderr);
+#endif
+ throwAprException(_E, APR_TIMEUP);
+ return;
+ }
}
#endif
if (no->pool)
@@ -280,6 +316,7 @@
no->opaque = NULL;
no->native = NULL;
}
+ apr_atomic_set32(&no->interrupted, 0);
} SIGHT_GLOBAL_END();
}
Show replies by date