diff options
author | Toshiaki Asai <toshi.alternative@gmail.com> | 2016-12-19 10:34:29 +0900 |
---|---|---|
committer | Toshiaki Asai <toshi.alternative@gmail.com> | 2016-12-19 10:34:29 +0900 |
commit | c3f1dff3d275ec220e5d804db5569a25b06ff3cd (patch) | |
tree | 37627c151081cee17e0746a02ea4f5257e521bac | |
parent | 1480cf729f1cc48befd141b05834673d1cdbc0b7 (diff) | |
download | mikutter-c3f1dff3d275ec220e5d804db5569a25b06ff3cd.tar.gz |
Reserverのタイムアウト時に作成されるThreadのclassを指定する引数を追加 refs #941
-rw-r--r-- | core/lib/reserver.rb | 7 | ||||
-rw-r--r-- | core/lib/retriever/mixin/photo_mixin.rb | 2 | ||||
-rw-r--r-- | core/mui/gtk_photo_pixbuf.rb | 2 | ||||
-rw-r--r-- | core/plugin/activity/activity.rb | 23 | ||||
-rw-r--r-- | core/plugin/api_request_file_cache.rb | 4 | ||||
-rw-r--r-- | core/plugin/gtk/gtk.rb | 11 | ||||
-rw-r--r-- | core/plugin/image_file_cache/image_file_cache.rb | 6 | ||||
-rw-r--r-- | core/plugin/ratelimit/ratelimit.rb | 2 | ||||
-rw-r--r-- | core/plugin/rest/rest.rb | 12 | ||||
-rw-r--r-- | core/plugin/skin/model/image.rb | 2 | ||||
-rw-r--r-- | core/plugin/streaming/filter.rb | 2 |
11 files changed, 42 insertions, 31 deletions
diff --git a/core/lib/reserver.rb b/core/lib/reserver.rb index a802ea84..a1a9c7a0 100644 --- a/core/lib/reserver.rb +++ b/core/lib/reserver.rb @@ -10,12 +10,13 @@ require 'delegate' class Reserver < Delegator - attr_reader :time + attr_reader :time, :thread_class alias __getobj__ time - def initialize(time, &proc) + def initialize(time, thread: Thread, &proc) raise ArgumentError.new('Block necessary for Reserver.new') unless block_given? @proc = proc + @thread_class = thread case when time.is_a?(Time) @time = time.freeze @@ -62,7 +63,7 @@ class Reserver < Delegator sleep_time = reserver.time - Time.now if sleep_time <= 0 @reservers.delete reserver - Thread.new(&reserver) + reserver.thread_class.new(&reserver) else Timeout.timeout(1 + sleep_time / 2, WakeUp){ Thread.stop } end rescue WakeUp diff --git a/core/lib/retriever/mixin/photo_mixin.rb b/core/lib/retriever/mixin/photo_mixin.rb index 8ad67c16..17b1b60a 100644 --- a/core/lib/retriever/mixin/photo_mixin.rb +++ b/core/lib/retriever/mixin/photo_mixin.rb @@ -186,7 +186,7 @@ module Retriever::Model::PhotoMixin # 既に動いているタイマーがあればそれをキャンセルする。 def set_forget_timer @forget.cancel if @forget - @forget = Reserver.new(forget_time){ forget! } + @forget = Reserver.new(forget_time, thread: SerialThread){ forget! } end # 覚えておりません diff --git a/core/mui/gtk_photo_pixbuf.rb b/core/mui/gtk_photo_pixbuf.rb index c05daa6b..c36cce1c 100644 --- a/core/mui/gtk_photo_pixbuf.rb +++ b/core/mui/gtk_photo_pixbuf.rb @@ -111,7 +111,7 @@ module Retriever::Model::PhotoMixin end def pixbuf_forget(width, height, gen) - Reserver.new([300, 60 * gen ** 2].max) do + Reserver.new([300, 60 * gen ** 2].max, thread: SerialThread) do pixbuf_cache.delete([width, height].hash) end end diff --git a/core/plugin/activity/activity.rb b/core/plugin/activity/activity.rb index 1512a379..a3420d67 100644 --- a/core/plugin/activity/activity.rb +++ b/core/plugin/activity/activity.rb @@ -72,16 +72,19 @@ Plugin.create(:activity) do # アクティビティの古い通知を一定時間後に消す def reset_activity(model) - Reserver.new(60) { - Delayer.new { - if not model.destroyed? - iters = model.to_enum(:each).to_a - remove_count = iters.size - UserConfig[:activity_max] - if remove_count > 0 - iters[-remove_count, remove_count].each{ |_m,_p,iter| - @contains_uris.delete(iter[ActivityView::URI]) - model.remove(iter) } end - reset_activity(model) end } } + Reserver.new(60, thread: Delayer) do + if not model.destroyed? + iters = model.to_enum(:each).to_a + remove_count = iters.size - UserConfig[:activity_max] + if remove_count > 0 + iters[-remove_count, remove_count].each do |_m,_p,iter| + @contains_uris.delete(iter[ActivityView::URI]) + model.remove(iter) + end + end + reset_activity(model) + end + end end def gen_listener_for_visible_check(uc, kind) diff --git a/core/plugin/api_request_file_cache.rb b/core/plugin/api_request_file_cache.rb index ac7be034..dce9aa76 100644 --- a/core/plugin/api_request_file_cache.rb +++ b/core/plugin/api_request_file_cache.rb @@ -5,10 +5,10 @@ Plugin.create(:api_request_file_cache) do def gc notice "apirequest cache was deleted. "+MikuTwitter::Cache.garbage_collect.inspect - Reserver.new(3600){ + Reserver.new(3600, thread: SerialThread){ gc } end - Reserver.new(3600){ gc } + Reserver.new(3600, thread: SerialThread){ gc } end diff --git a/core/plugin/gtk/gtk.rb b/core/plugin/gtk/gtk.rb index 033ac70b..33957e97 100644 --- a/core/plugin/gtk/gtk.rb +++ b/core/plugin/gtk/gtk.rb @@ -375,15 +375,18 @@ Plugin.create :gtk do on_gui_window_rewindstatus do |i_window, text, expire| window = @slug_dictionary.get(Plugin::GUI::Window, :default) - if not window - next end + next if not window statusbar = window.statusbar cid = statusbar.get_context_id("system") mid = statusbar.push(cid, text) if expire != 0 - Reserver.new(expire){ + Reserver.new(expire, thread: Delayer) do if not statusbar.destroyed? - statusbar.remove(cid, mid) end } end end + statusbar.remove(cid, mid) + end + end + end + end on_gui_child_activated do |i_parent, i_child, activated_by_toolkit| type_strict i_parent => Plugin::GUI::HierarchyParent, i_child => Plugin::GUI::HierarchyChild diff --git a/core/plugin/image_file_cache/image_file_cache.rb b/core/plugin/image_file_cache/image_file_cache.rb index 6592c62b..883de98d 100644 --- a/core/plugin/image_file_cache/image_file_cache.rb +++ b/core/plugin/image_file_cache/image_file_cache.rb @@ -52,7 +52,7 @@ Plugin.create :image_file_cache do .map{|x| File.join(dir, x) } .select{|x| FileTest.file?(x) } .each{|x| - Reserver.new((File.atime(x) rescue File.mtime(x)) + cache_expire) do + Reserver.new((File.atime(x) rescue File.mtime(x)) + cache_expire, thread: SerialThread) do notice "cache deleted #{x}" File.delete(x) if FileTest.file?(x) if Dir.foreach(dir).select{|y| File.file? File.join(dir, y) }.empty? @@ -69,13 +69,13 @@ Plugin.create :image_file_cache do .each{|subdir| check_subdirs(File.join(@cache_directory, subdir)) } - Reserver.new(cache_expire) do + Reserver.new(cache_expire, thread: SerialThread) do check_dirs end end end def _loop - Reserver.new(60) do + Reserver.new(60, thread: SerialThread) do if @queue @queue.run _loop end end end diff --git a/core/plugin/ratelimit/ratelimit.rb b/core/plugin/ratelimit/ratelimit.rb index 516b413a..326ad1f0 100644 --- a/core/plugin/ratelimit/ratelimit.rb +++ b/core/plugin/ratelimit/ratelimit.rb @@ -37,7 +37,7 @@ Plugin.create :ratelimit do Plugin.filter_cancel! else notificated << ratelimit - Reserver.new(ratelimit.reset){ notificated.delete(ratelimit) } end } + Reserver.new(ratelimit.reset, thread: Thread){ notificated.delete(ratelimit) } end } [service, ratelimit] end diff --git a/core/plugin/rest/rest.rb b/core/plugin/rest/rest.rb index f78dad29..ea1333de 100644 --- a/core/plugin/rest/rest.rb +++ b/core/plugin/rest/rest.rb @@ -29,10 +29,14 @@ Plugin.create :rest do @account_observer.detach @account_observer = nil end else - Service.instances.each { |service| - @crawlers.each{ |s| s.call(service) } } - ::Reserver.new(60){ - start } end end + Service.instances.each do |service| + @crawlers.each{ |s| s.call(service) } + end + Reserver.new(60, thread: Delayer) do + start + end + end + end Delayer.new{ start } end diff --git a/core/plugin/skin/model/image.rb b/core/plugin/skin/model/image.rb index e6b63586..40bf747b 100644 --- a/core/plugin/skin/model/image.rb +++ b/core/plugin/skin/model/image.rb @@ -37,7 +37,7 @@ module Plugin::Skin def pixbuf_forget(width, height, gen) unless width == height and [12, 16, 24, 32, 48, 64].include?(width) - Reserver.new([300, 60 * gen ** 2].max) do + Reserver.new([300, 60 * gen ** 2].max, thread: SerialThread) do pixbuf_cache.delete([width, height].hash) end end diff --git a/core/plugin/streaming/filter.rb b/core/plugin/streaming/filter.rb index 66467ea6..da8678e0 100644 --- a/core/plugin/streaming/filter.rb +++ b/core/plugin/streaming/filter.rb @@ -15,7 +15,7 @@ Plugin.create :streaming do on_filter_stream_reconnect_request do if not reconnect_request_flag reconnect_request_flag = true - Reserver.new(30) { + Reserver.new(30, thread: Delayer) { reconnect_request_flag = false Plugin.call(:filter_stream_force_retry) } end end |