]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
rss plugin: lock the mutex on more occasions
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 20 Mar 2007 00:27:55 +0000 (00:27 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 20 Mar 2007 00:27:55 +0000 (00:27 +0000)
data/rbot/plugins/rss.rb

index caebc3fc6795465671dd3cbd62c547cbbab2f181..691894171c50c7b4fffbf9e42597af3fbd1e1538 100644 (file)
@@ -53,11 +53,13 @@ class ::RssBlob
   end\r
 \r
   def dup\r
-    self.class.new(@url,\r
-                   @handle,\r
-                   @type ? @type.dup : nil,\r
-                   @watchers.dup,\r
-                   @xml ? @xml.dup : nil)\r
+    @mutex.synchronize do\r
+      self.class.new(@url,\r
+                     @handle,\r
+                     @type ? @type.dup : nil,\r
+                     @watchers.dup,\r
+                     @xml ? @xml.dup : nil)\r
+    end\r
   end\r
 \r
   # Downcase all watchers, possibly turning them into Strings if they weren't\r
@@ -81,12 +83,16 @@ class ::RssBlob
     if watched_by?(who)\r
       return nil\r
     end\r
-    @watchers << who.downcase\r
+    @mutex.synchronize do\r
+      @watchers << who.downcase\r
+    end\r
     return who\r
   end\r
 \r
   def rm_watch(who)\r
-    @watchers.delete(who.downcase)\r
+    @mutex.synchronize do\r
+      @watchers.delete(who.downcase)\r
+    end\r
   end\r
 \r
   def to_a\r
@@ -151,9 +157,7 @@ class RSSFeedsPlugin < Plugin
   def save\r
     unparsed = Hash.new()\r
     @feeds.each { |k, f|\r
-      f.mutex.synchronize do\r
-        unparsed[k] = f.dup\r
-      end\r
+      unparsed[k] = f.dup\r
     }\r
     @registry[:feeds] = unparsed\r
   end\r