diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-04 16:38:34 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-04 16:38:34 +0000 |
commit | c0359f81764e30ad041b152aeea1a2c0a95c3ccb (patch) | |
tree | fa7f805dedc13b163e2eb926282700070636ed74 /test | |
parent | 1d6bd86acd77ad4dde428ca53878ae0b24b487ed (diff) | |
download | ruby-c0359f81764e30ad041b152aeea1a2c0a95c3ccb.tar.gz |
* io.c (io_cntl, nogvl_io_cntl): IO.fcntl() and IO.ioctl()
release GVL during calling kernel interface.
Suggested by Eric Wong. [ruby-core:35417][Bug #4463]
* test/ruby/test_io.rb (TestIO#test_fcntl_lock): add new test for
IO.fcntl().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_io.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 6cc2897f5f..a0f1569895 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1776,4 +1776,38 @@ End end end end + + + if /x86_64-linux/ =~ RUBY_PLATFORM # A binary form of struct flock depend on platform + F_WRLCK = 1 + F_UNLCK = 2 + SEEK_SET = 0 + + def test_fcntl_lock + pad = 0 + flocktype = "s!s!s!s!L!L!i!" + + Tempfile.open(self.class.name) do |f| + r, w = IO.pipe + pid = fork do + r.close + lock = [F_WRLCK, SEEK_SET, pad, pad, 0, 0, 0].pack(flocktype) + f.fcntl Fcntl::F_SETLKW, lock + w.syswrite "." + sleep + end + w.close + assert_equal ".", r.read(1) + r.close + pad = 0 + getlock = [F_WRLCK, 0, pad, pad, 0, 0, 0].pack(flocktype) + f.fcntl Fcntl::F_GETLK, getlock + + ptype, whence, pad, pad, start, len, lockpid = getlock.unpack(flocktype) + assert_equal(pid, lockpid) + Process.kill :TERM, pid + Process.waitpid2(pid) + end + end + end end |