Skip to content

Commit c67f62d

Browse files
committed
[js] Implement nqp::lockfh/nqp::unlockfh
1 parent 69085fb commit c67f62d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/vm/js/Operations.nqp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ class QAST::OperationsJS {
488488
add_simple_op('rename', $T_VOID, [$T_STR, $T_STR], :side_effects);
489489
add_simple_op('filenofh', $T_INT, [$T_OBJ]);
490490

491+
add_simple_op('lockfh', $T_OBJ, [$T_OBJ, $T_INT], :side_effects);
492+
add_simple_op('unlockfh', $T_OBJ, [$T_OBJ], :side_effects);
493+
491494
add_simple_op('bootarray', $T_OBJ, []);
492495

493496
add_simple_op('getpid', $T_INT, []);

src/vm/js/nqp-runtime/io.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,13 @@ op.copy = function(source, target) {
607607
op.rename = function(oldPath, newPath) {
608608
fs.renameSync(oldPath, newPath);
609609
};
610+
611+
op.lockfh = function(fh, flags) {
612+
fs.flockSync(fh.fd, (flags & 0x01 ? 'sh' : 'ex') + (flags & 0x10 ? 'nb' : ''));
613+
return fh;
614+
};
615+
616+
op.unlockfh = function(fh, flags) {
617+
fs.flockSync(fh.fd, 'un');
618+
return fh;
619+
};

0 commit comments

Comments
 (0)