From 3a109d1c82047dfda01eb7af3d815bf655cc8a4d Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Tue, 23 Dec 2008 16:27:34 -0600 Subject: [PATCH] Thread Safety Use "Thread.current[:included_by]" instead of the Class variable, "@@included_by". The former will work on some newfangled multi-threaded Webserver stack, which uses separate threads to handle multiple simlutaneous requests (one request/thread). Dunno that the rest of the application is thread-safe, but using a class variable, in this context, probably isn't. Thanks to Sam Ruby for the suggestion. --- lib/chunks/include.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/chunks/include.rb b/lib/chunks/include.rb index 3a64946c..7ec8aba9 100644 --- a/lib/chunks/include.rb +++ b/lib/chunks/include.rb @@ -10,14 +10,14 @@ require 'chunks/wiki' class Include < WikiChunk::WikiReference INCLUDE_PATTERN = /\[\[!include\s+([^\]\s][^\]]+?)\s*\]\]/i - @@included_by = [] + Thread.current[:included_by] = [] def self.pattern() INCLUDE_PATTERN end def initialize(match_data, content) super @page_name = match_data[1].strip rendering_mode = content.options[:mode] || :show - @@included_by.push(@content.page_name) + Thread.current[:included_by].push(@content.page_name) @unmask_text = get_unmask_text_avoiding_recursion_loops(rendering_mode) end @@ -25,9 +25,9 @@ class Include < WikiChunk::WikiReference def get_unmask_text_avoiding_recursion_loops(rendering_mode) if refpage - if @@included_by.include?(refpage.page.name) + if Thread.current[:included_by].include?(refpage.page.name) @content.delete_chunk(self) - @@included_by = [] + Thread.current[:included_by] = [] return "Recursive include detected: #{@content.page_name} → #{@content.page_name}\n" end # TODO This way of instantiating a renderer is ugly. @@ -41,10 +41,10 @@ class Include < WikiChunk::WikiReference raise "Unsupported rendering mode #{@mode.inspect}" end @content.merge_chunks(included_content) - @@included_by = [] + Thread.current[:included_by] = [] return included_content.pre_rendered else - @@included_by = [] + Thread.current[:included_by] = [] return "Could not include #{@page_name}\n" end end