whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Default to shared read
Date Thu, 05 Jul 2018 00:27:35 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 3af13d5  Default to shared read
3af13d5 is described below

commit 3af13d52f6ccb73f7e8bcd7637ead30b247c0800
Author: Sebb <sebb@apache.org>
AuthorDate: Thu Jul 5 01:27:33 2018 +0100

    Default to shared read
---
 lib/whimsy/lockfile.rb | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/whimsy/lockfile.rb b/lib/whimsy/lockfile.rb
index 02fafbf..85069f8 100644
--- a/lib/whimsy/lockfile.rb
+++ b/lib/whimsy/lockfile.rb
@@ -33,9 +33,12 @@ module LockFile
   end
 
   # open a file and lock it
-  def self.lockfile(filename, mode, lockmode)
-    open(filename, mode) do |f|
-      self.flock(f, lockmode) { |g|
+  # filename
+  # mode: default 'r'
+  # lockmode: default LOCK_SH
+  def self.lockfile(filename, mode=nil, lockmode=nil)
+    open(filename, mode || 'r') do |f|
+      self.flock(f, lockmode || File::LOCK_SH) { |g|
         yield g
       }
     end
@@ -52,6 +55,14 @@ if __FILE__ == $0
   puts "#{Time.now} #{test} using #{name}"
   ret = nil
   case test
+  when 'default'
+    puts "#{Time.now} Wait lock"
+    ret = LockFile.lockfile(name) do |f|
+      puts "#{Time.now} Got lock"
+      puts f.read
+      puts "#{Time.now} Sleep"
+      sleep(5)
+    end
   when 'create'
     ret = LockFile.create_ex(name) {|f| f << text}
   when 'opena'


Mime
View raw message