summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-06-05 01:56:47 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-06-05 01:56:47 +0000
commita9f672c47b9482b922a5df2b8800fd8a22f67680 (patch)
tree11a1515875e0b28e2b8741836033c3d49ba38fd9
parent160a9f79ef3f106786a3a97552e23a0fd840899f (diff)
* tcltklib.c:
Stop the running zombi-eventloop when mainloop_watchdog is killed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/tcltklib/tcltklib.c68
1 files changed, 42 insertions, 26 deletions
diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c
index c22893ae37..9ff5972910 100644
--- a/ext/tcltklib/tcltklib.c
+++ b/ext/tcltklib/tcltklib.c
@@ -202,19 +202,18 @@ lib_mainloop_core(check_root_widget)
return Qnil;
}
-
VALUE
lib_mainloop_ensure(parent_evloop)
VALUE parent_evloop;
{
- if (ruby_debug) {
- fprintf(stderr, "tcltklib: eventloop-thread : %lx -> %lx\n",
- eventloop_thread, parent_evloop);
- }
-
Tk_DeleteTimerHandler(timer_token);
timer_token = (Tcl_TimerToken)NULL;
- eventloop_thread = parent_evloop;
+ DUMP2("mainloop-ensure: current-thread : %lx\n", rb_thread_current());
+ DUMP2("mainloop-ensure: eventloop-thread : %lx\n", eventloop_thread);
+ if (eventloop_thread == rb_thread_current()) {
+ DUMP2("tcltklib: eventloop-thread -> %lx\n", parent_evloop);
+ eventloop_thread = parent_evloop;
+ }
return Qnil;
}
@@ -255,26 +254,14 @@ lib_mainloop(argc, argv, self)
return lib_mainloop_launcher(check_rootwidget);
}
-static VALUE
-lib_mainloop_watchdog(argc, argv, self)
- int argc;
- VALUE *argv;
- VALUE self;
-{
+VALUE
+lib_watchdog_core(check_rootwidget)
VALUE check_rootwidget;
+{
+ VALUE current = eventloop_thread;
VALUE evloop;
- int check;
- ID stop;
-
- if (rb_scan_args(argc, argv, "01", &check_rootwidget) == 0) {
- check_rootwidget = Qtrue;
- } else if (RTEST(check_rootwidget)) {
- check_rootwidget = Qtrue;
- } else {
- check_rootwidget = Qfalse;
- }
- check = (check_rootwidget == Qtrue);
- stop = rb_intern("stop?");
+ int check = (check_rootwidget == Qtrue);
+ ID stop = rb_intern("stop?");
/* check other watchdog thread */
if (watchdog_thread != 0) {
@@ -296,13 +283,42 @@ lib_mainloop_watchdog(argc, argv, self)
(void*)&check_rootwidget);
DUMP2("create new eventloop thread %lx", evloop);
rb_thread_run(evloop);
+ } else {
+ rb_thread_schedule();
}
- rb_thread_schedule();
} while(!check || Tk_GetNumMainWindows() != 0);
return Qnil;
}
+VALUE
+lib_watchdog_ensure(arg)
+ VALUE arg;
+{
+ eventloop_thread = 0; /* stop eventloops */
+ return Qnil;
+}
+
+static VALUE
+lib_mainloop_watchdog(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE check_rootwidget;
+
+ if (rb_scan_args(argc, argv, "01", &check_rootwidget) == 0) {
+ check_rootwidget = Qtrue;
+ } else if (RTEST(check_rootwidget)) {
+ check_rootwidget = Qtrue;
+ } else {
+ check_rootwidget = Qfalse;
+ }
+
+ return rb_ensure(lib_watchdog_core, check_rootwidget,
+ lib_watchdog_ensure, Qnil);
+}
+
static VALUE
lib_do_one_event(argc, argv, self)
int argc;