Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created April 16, 2017 04:13
Show Gist options
  • Save zoffixznet/3f0183192c4fb4d8e2b8e9c58c6f226e to your computer and use it in GitHub Desktop.
Save zoffixznet/3f0183192c4fb4d8e2b8e9c58c6f226e to your computer and use it in GitHub Desktop.
cpan@perlbuild2~/CPANPRC/rakudo (nom)$ gd
diff --git a/src/core/Exception.pm b/src/core/Exception.pm
index 3f7339b..7a4b22c 100644
--- a/src/core/Exception.pm
+++ b/src/core/Exception.pm
@@ -466,6 +466,12 @@ my class X::IO::Copy does X::IO {
}
}
+my class X::IO::Lock does X::IO {
+ has Str $.lock-type;
+ has Str $.os-error;
+ method message() { "Could not obtain $.lock-type lock: $.os-error" }
+}
+
my class X::IO::Move does X::IO {
has $.from;
has $.to;
diff --git a/src/core/IO/Handle.pm b/src/core/IO/Handle.pm
index 4c24478..e3e0658 100644
--- a/src/core/IO/Handle.pm
+++ b/src/core/IO/Handle.pm
@@ -753,8 +753,13 @@ 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, Bool:D :$shared --> 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) {
cpan@perlbuild2~/CPANPRC/rakudo (nom)$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment