Skip to content

Commit

Permalink
[js] Implement nqp::lockfh/nqp::unlockfh
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed May 17, 2017
1 parent 69085fb commit c67f62d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/vm/js/Operations.nqp
Expand Up @@ -488,6 +488,9 @@ class QAST::OperationsJS {
add_simple_op('rename', $T_VOID, [$T_STR, $T_STR], :side_effects);
add_simple_op('filenofh', $T_INT, [$T_OBJ]);

add_simple_op('lockfh', $T_OBJ, [$T_OBJ, $T_INT], :side_effects);
add_simple_op('unlockfh', $T_OBJ, [$T_OBJ], :side_effects);

add_simple_op('bootarray', $T_OBJ, []);

add_simple_op('getpid', $T_INT, []);
Expand Down
10 changes: 10 additions & 0 deletions src/vm/js/nqp-runtime/io.js
Expand Up @@ -607,3 +607,13 @@ op.copy = function(source, target) {
op.rename = function(oldPath, newPath) {
fs.renameSync(oldPath, newPath);
};

op.lockfh = function(fh, flags) {
fs.flockSync(fh.fd, (flags & 0x01 ? 'sh' : 'ex') + (flags & 0x10 ? 'nb' : ''));
return fh;
};

op.unlockfh = function(fh, flags) {
fs.flockSync(fh.fd, 'un');
return fh;
};

0 comments on commit c67f62d

Please sign in to comment.