From 382b4ae9a34c2f697464e1e42fd0fdc277fdd3c3 Mon Sep 17 00:00:00 2001 From: nagai Date: Tue, 14 Oct 2003 15:25:45 +0000 Subject: ext/tcltklib/tcltklib.c: * replace Tcl/Tk's vwait and tkwait to switch on threads smoothly and avoid seg-fault. * add TclTkIp._thread_vwait and _thread_tkwait for waiting on a thread. ( Because Tcl/Tk's vwait and tkwait command wait on a eventloop. ) ext/tk/lib/multi-tk.rb: * support TclTkIp._thread_vwait and _thread_tkwait ext/tk/lib/tk.rb: * now, TkVariable#wait has 2 arguments. If 1st argument is true, waits on a thread. If false, waits on an eventloop. If 2nd argument is true, checks existence of rootwidgets. If false, doesn't. Default is wait(true, false). * add TkVariable#tkwait(arg) which is equal to TkVariable#wait(arg, true) * wait_visibility and wait_destroy have an argument for waiting on a thread or an eventloop. * improve of accessing Tcl/Tk's special variables ext/tk/lib/tkafter.rb: * support 'wait on a thread' and 'wait on an eventloop' git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tkafter.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'ext/tk/lib/tkafter.rb') diff --git a/ext/tk/lib/tkafter.rb b/ext/tk/lib/tkafter.rb index 239db4b5c9..663b977ed2 100644 --- a/ext/tk/lib/tkafter.rb +++ b/ext/tk/lib/tkafter.rb @@ -82,6 +82,7 @@ class TkTimer if @running == false || @proc_max == 0 || @do_loop == 0 Tk_CBTBL.delete(@id) ;# for GC @running = false + @wait_var.value = 0 return end if @current_pos >= @proc_max @@ -90,6 +91,7 @@ class TkTimer else Tk_CBTBL.delete(@id) ;# for GC @running = false + @wait_var.value = 0 return end end @@ -114,6 +116,8 @@ class TkTimer @id = Tk_CBID.join Tk_CBID[1].succ! + @wait_var = TkVariable.new(0) + # @cb_cmd = TkCore::INTERP.get_cb_entry(self.method(:do_callback)) @cb_cmd = TkCore::INTERP.get_cb_entry(proc{ begin @@ -338,6 +342,7 @@ class TkTimer def cancel @running = false + @wait_var.value = 0 tk_call 'after', 'cancel', @after_id if @after_id @after_id = nil Tk_CBTBL.delete(@id) ;# for GC @@ -378,6 +383,30 @@ class TkTimer nil end end + + def wait(on_thread = true, check_root = false) + if $SAFE >= 4 + fail SecurityError, "can't wait timer at $SAFE >= 4" + end + return self unless @running + @wait_var.wait(on_thread, check_root) + self + end + def eventloop_wait(check_root = false) + wait(false, check_root) + end + def thread_wait(check_root = false) + wait(true, check_root) + end + def tkwait(on_thread = true) + wait(on_thread, true) + end + def eventloop_tkwait + wait(false, true) + end + def thread_tkwait + wait(true, true) + end end TkAfter = TkTimer -- cgit v1.2.3