• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Ruby GTK3移行後のメインリポジトリ


コミットメタ情報

リビジョン521f3c11303ce05ab15b604fb14b293eb212e000 (tree)
日時2014-04-08 21:49:33
作者Shyouzou Sugitani <shy@user...>
コミッターShyouzou Sugitani

ログメッセージ

add lock.rb

変更サマリ

差分

--- a/lib/ninix/alias.rb
+++ b/lib/ninix/alias.rb
@@ -124,6 +124,7 @@ module Alias
124124 end
125125
126126 class TEST
127+
127128 def initialize(path)
128129 conf = Alias::create_from_file(path)
129130 print("ALIAS: ", conf, "\n")
--- /dev/null
+++ b/lib/ninix/lock.rb
@@ -0,0 +1,43 @@
1+# -*- coding: utf-8 -*-
2+#
3+# Copyright (C) 2011-2014 by Shyouzou Sugitani <shy@users.sourceforge.jp>
4+#
5+# This program is free software; you can redistribute it and/or modify it
6+# under the terms of the GNU General Public License (version 2) as
7+# published by the Free Software Foundation. It is distributed in the
8+# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
9+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+# PURPOSE. See the GNU General Public License for more details.
11+#
12+
13+module Lock
14+
15+ def self.lockfile(fileobj)
16+ fileobj.flock(File::LOCK_EX | File::LOCK_NB)
17+ end
18+
19+ def self.unlockfile(fileobj)
20+ fileobj.flock(File::LOCK_UN)
21+ end
22+
23+
24+ class TEST
25+
26+ def initialize(path)
27+ f = open(path, "w")
28+ if Lock.lockfile(f)
29+ print("LOCK\n")
30+ sleep(5)
31+ Lock.unlockfile(f)
32+ print("UNLOCK\n")
33+ else
34+ print("LOCK: failed.\n")
35+ end
36+ f.close
37+ end
38+ end
39+end
40+
41+$:.unshift(File.dirname(__FILE__))
42+
43+Lock::TEST.new(ARGV.shift)