summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/pstore.rb16
2 files changed, 18 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 69b1b86361..bb7a4e7cfa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Nov 11 12:56:34 2012 Masaki Matsushita <glass.saga@gmail.com>
+
+ * lib/pstore.rb (PStore): fix not to replace ThreadError raised in
+ #transaction block with PStore::Error.
+ [ruby-core:39238] [Bug #5269]
+
Sun Nov 11 11:36:19 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo):
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