ruby-changes:19728
From: yugui <ko1@a...>
Date: Sun, 29 May 2011 08:32:22 +0900 (JST)
Subject: [ruby-changes:19728] yugui:r31773 (ruby_1_9_2): merges r31050 from trunk into ruby_1_9_2.
yugui 2011-05-29 08:32:10 +0900 (Sun, 29 May 2011) New Revision: 31773 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31773 Log: merges r31050 from trunk into ruby_1_9_2. -- * lib/pstore.rb: Delete variable @transaction and fix #4474. Patch by Masaki Matsushita (Glass_saga). * test/test_pstore.rb(test_thread_safe): Add test for #4474. Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/lib/pstore.rb branches/ruby_1_9_2/test/test_pstore.rb branches/ruby_1_9_2/version.h Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 31772) +++ ruby_1_9_2/ChangeLog (revision 31773) @@ -1,3 +1,10 @@ +Mon Mar 7 22:59:39 2011 Shota Fukumori <sorah@t...> + + * lib/pstore.rb: Delete variable @transaction and fix #4474. Patch by + Masaki Matsushita (Glass_saga). + + * test/test_pstore.rb(test_thread_safe): Add test for #4474. + Sat Mar 5 22:54:36 2011 CHIKANAGA Tomoyuki <nagachika00@g...> * include/ruby/intern.h: fix a typo of prototype declaration. Index: ruby_1_9_2/lib/pstore.rb =================================================================== --- ruby_1_9_2/lib/pstore.rb (revision 31772) +++ ruby_1_9_2/lib/pstore.rb (revision 31773) @@ -127,21 +127,16 @@ if File::exist? file and not File::readable? file raise PStore::Error, format("file %s not readable", file) end - @transaction = false @filename = file @abort = false @ultra_safe = false @thread_safe = thread_safe - if @thread_safe - @lock = Mutex.new - else - @lock = DummyMutex.new - end + @lock = Mutex.new end # Raises PStore::Error if the calling code is not in a PStore#transaction. def in_transaction - raise PStore::Error, "not in transaction" unless @transaction + raise PStore::Error, "not in transaction" unless @lock.locked? end # # Raises PStore::Error if the calling code is not in a PStore#transaction or @@ -318,10 +313,9 @@ # def transaction(read_only = false, &block) # :yields: pstore value = nil - raise PStore::Error, "nested transaction" if @transaction + raise PStore::Error, "nested transaction" if !@thread_safe && @lock.locked? @lock.synchronize do @rdonly = read_only - @transaction = true @abort = false file = open_and_lock_file(@filename, read_only) if file @@ -347,8 +341,6 @@ end end value - ensure - @transaction = false end private @@ -357,12 +349,6 @@ EMPTY_MARSHAL_DATA = Marshal.dump({}) EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA) - class DummyMutex - def synchronize - yield - end - end - # # Open the specified filename (either in read-only mode or in # read-write mode) and lock it for reading or writing. Index: ruby_1_9_2/version.h =================================================================== --- ruby_1_9_2/version.h (revision 31772) +++ ruby_1_9_2/version.h (revision 31773) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 211 +#define RUBY_PATCHLEVEL 212 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_2/test/test_pstore.rb =================================================================== --- ruby_1_9_2/test/test_pstore.rb (revision 31772) +++ ruby_1_9_2/test/test_pstore.rb (revision 31773) @@ -71,4 +71,33 @@ end end end + + def test_thread_safe + assert_raise(PStore::Error) do + flag = false + Thread.new do + @pstore.transaction do + @pstore[:foo] = "bar" + flag = true + sleep 1 + end + end + until flag; end + @pstore.transaction {} + end + assert_block do + pstore = PStore.new("pstore.tmp2.#{Process.pid}",true) + flag = false + Thread.new do + pstore.transaction do + pstore[:foo] = "bar" + flag = true + sleep 1 + end + end + until flag; end + pstore.transaction { pstore[:foo] == "bar" } + File.unlink("pstore.tmp2.#{Process.pid}") rescue nil + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/