summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tkafter.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-14 15:25:45 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-14 15:25:45 +0000
commit382b4ae9a34c2f697464e1e42fd0fdc277fdd3c3 (patch)
tree2411731a86321077cae6101089d0e76f96c97cb4 /ext/tk/lib/tkafter.rb
parent6adad139461f64d6bc011df2236d21f53c5fac8c (diff)
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
Diffstat (limited to 'ext/tk/lib/tkafter.rb')
-rw-r--r--ext/tk/lib/tkafter.rb29
1 files changed, 29 insertions, 0 deletions
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