summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorsorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-07 14:03:41 +0000
committersorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-07 14:03:41 +0000
commite267617f3e359cf40a28ba3baa360b9cd7ca2bf2 (patch)
tree2f6bb47cb99c3652ad95c8be59f3d9f0e5f22171 /lib
parent52b40be04b961a38379d559b3a10d8a6252ba43b (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/pstore.rb20
1 files changed, 3 insertions, 17 deletions
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 65cce7b238..3114eb567f 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -127,21 +127,16 @@ class PStore
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 @@ class PStore
#
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 @@ class PStore
end
end
value
- ensure
- @transaction = false
end
private
@@ -357,12 +349,6 @@ class PStore
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.