summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-11 04:23:04 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-11 04:23:04 +0000
commitfc4b6cd25f231d19851cd256b7c0ad1fe06000d9 (patch)
tree1a0775ed1d36c33da1050fbb46dc546a42f8390b /lib
parentba5ea548cefd82307e96a6308e2b85425030e461 (diff)
* lib/pstore.rb (PStore): fix not to replace ThreadError raised in
#transaction block with PStore::Error. [ruby-core:39238] [Bug #5269] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/pstore.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/pstore.rb b/lib/pstore.rb
index d717820847..a2813a8e20 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -309,8 +309,16 @@ class PStore
#
def transaction(read_only = false) # :yields: pstore
value = nil
- raise PStore::Error, "nested transaction" if !@thread_safe && @lock.locked?
- @lock.synchronize do
+ if !@thread_safe
+ raise PStore::Error, "nested transaction" unless @lock.try_lock
+ else
+ begin
+ @lock.lock
+ rescue ThreadError
+ raise PStore::Error, "nested transaction"
+ end
+ end
+ begin
@rdonly = read_only
@abort = false
file = open_and_lock_file(@filename, read_only)
@@ -335,10 +343,10 @@ class PStore
value = yield(self)
end
end
+ ensure
+ @lock.unlock
end
value
- rescue ThreadError
- raise PStore::Error, "nested transaction"
end
private