summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pstore.rb11
-rw-r--r--lib/singleton.rb1
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 2aa9864b5..cc90207aa 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -78,6 +78,16 @@ class PStore
begin
@transaction = true
value = file = nil
+ lock = @filename + ".lock"
+ loop do
+ begin
+ File::symlink("pstore::#$$", lock)
+ break
+ rescue Errno::EEXIST
+ rescue
+ sleep 1
+ end
+ end
begin
File::open(@filename, "r") do |file|
@table = Marshal.load(file)
@@ -112,6 +122,7 @@ class PStore
ensure
@table = nil
@transaction = false
+ File::unlink(lock)
end
value
end
diff --git a/lib/singleton.rb b/lib/singleton.rb
index 8167a01aa..4aea574e7 100644
--- a/lib/singleton.rb
+++ b/lib/singleton.rb
@@ -14,6 +14,7 @@ module Singleton
def Singleton.append_features(klass)
klass.private_class_method(:new)
klass.instance_eval %{
+ @__instance__ = nil
def instance
unless @__instance__
@__instance__ = new