Ruby GTK3移行後のメインリポジトリ
リビジョン | 521f3c11303ce05ab15b604fb14b293eb212e000 (tree) |
---|---|
日時 | 2014-04-08 21:49:33 |
作者 | Shyouzou Sugitani <shy@user...> |
コミッター | Shyouzou Sugitani |
add lock.rb
@@ -124,6 +124,7 @@ module Alias | ||
124 | 124 | end |
125 | 125 | |
126 | 126 | class TEST |
127 | + | |
127 | 128 | def initialize(path) |
128 | 129 | conf = Alias::create_from_file(path) |
129 | 130 | print("ALIAS: ", conf, "\n") |
@@ -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) |