Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[io grant] Implement proper args for IO::Handle.lock
  • Loading branch information
zoffixznet committed Apr 16, 2017
1 parent b7c036c commit 214198b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/CompUnit/PrecompilationStore/File.pm
Expand Up @@ -121,7 +121,7 @@ class CompUnit::PrecompilationStore::File does CompUnit::PrecompilationStore {
$!lock //= $.prefix.concat-with('.lock').open(:create, :rw);
$!lock-count++
}
$!lock.lock(2) if $acquire-file-lock == 0;
$!lock.lock if $acquire-file-lock == 0;
}

method unlock() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/CompUnit/Repository/Installation.pm
Expand Up @@ -227,7 +227,7 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
my @*MODULES;
my $path = self!writeable-path or die "No writeable path found, $.prefix not writeable";
my $lock = $.prefix.concat-with('repo.lock').open(:create, :w);
$lock.lock(2);
$lock.lock;

my $version = self!repository-version;
self.upgrade-repository unless $version == 2;
Expand Down
5 changes: 5 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -466,6 +466,11 @@ my class X::IO::Copy does X::IO {
}
}

my class X::IO::Lock does X::IO {
has $.lock-type;
method message() { "Could not obtain $.lock-type lock: $.os-error" }
}

my class X::IO::Move does X::IO {
has $.from;
has $.to;
Expand Down
11 changes: 9 additions & 2 deletions src/core/IO/Handle.pm
Expand Up @@ -753,8 +753,15 @@ my class IO::Handle {
self.opened && nqp::p6bool(nqp::isttyfh($!PIO))
}

method lock(IO::Handle:D: Int:D $flag) {
nqp::lockfh($!PIO, $flag)
method lock(IO::Handle:D:
Bool:D :$non-blocking = False, Bool:D :$shared = False --> True
) {
nqp::lockfh($!PIO, 0x10*$non-blocking + $shared);
CATCH { default {
fail X::IO::Lock.new: :os-error(.Str),
:lock-type( 'non-' x $non-blocking ~ 'blocking, '
~ ($shared ?? 'shared' !! 'exclusive') );
}}
}

method unlock(IO::Handle:D: --> True) {
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -976,6 +976,7 @@ S32-io/dir.t
S32-io/file-tests.t
S32-io/indir.t
S32-io/io-handle.t
S32-io/lock.t # slow
S32-io/socket-host-port-split.t
S32-io/socket-fail-invalid-values.t
S32-io/io-special.t
Expand Down

0 comments on commit 214198b

Please sign in to comment.