Skip to content

Commit

Permalink
Uses F_NOCACHE for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
genki committed Aug 10, 2013
1 parent 71c0d6d commit 72d0710
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
$CPPFLAGS += " -DHAVE_O_DIRECT_MACRO"
end

if have_macro("F_NOCACHE", %w(fcntl.h))
$CPPFLAGS += " -DHAVE_F_NOCACHE_MACRO"
end

create_makefile('io/extra', 'io')
19 changes: 16 additions & 3 deletions ext/io/extra.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static VALUE io_fdwalk(int argc, VALUE* argv, VALUE klass){
}
#endif

#if defined(HAVE_DIRECTIO) || defined(O_DIRECT)
#if defined(HAVE_DIRECTIO) || defined(O_DIRECT) || defined(F_NOCACHE)
/*
* call-seq:
* IO#directio?
Expand All @@ -258,7 +258,7 @@ static VALUE io_fdwalk(int argc, VALUE* argv, VALUE klass){
* current handle. The default is false.
*/
static VALUE io_get_directio(VALUE self){
#if defined(HAVE_DIRECTIO)
#if defined(HAVE_DIRECTIO) || defined(F_NOCACHE)
VALUE v_advice = Qnil;

if(rb_ivar_defined(rb_cIO, rb_intern("@directio")))
Expand Down Expand Up @@ -309,6 +309,7 @@ static VALUE io_set_directio(VALUE self, VALUE v_advice){
rb_iv_set(self, "directio", Qtrue);
#else
{
#if defined(O_DIRECT)
int flags = fcntl(fd, F_GETFL);

if(flags < 0)
Expand All @@ -325,6 +326,18 @@ static VALUE io_set_directio(VALUE self, VALUE v_advice){
rb_sys_fail("fcntl");
}
}
#elif defined(F_NOCACHE)
if(advice == DIRECTIO_OFF){
if(fcntl(fd, F_NOCACHE, 0) < 0)
rb_sys_fail("fcntl");
} else { /* DIRECTIO_ON*/
if(fcntl(fd, F_NOCACHE, 1) < 0)
rb_sys_fail("fcntl");
}

if(advice == DIRECTIO_ON)
rb_iv_set(self, "directio", Qtrue);
#endif
}
#endif

Expand Down Expand Up @@ -592,7 +605,7 @@ void Init_extra(){
rb_define_singleton_method(rb_cIO, "fdwalk", io_fdwalk, -1);
#endif

#if defined(HAVE_DIRECTIO) || defined(O_DIRECT)
#if defined(HAVE_DIRECTIO) || defined(O_DIRECT) || defined(F_NOCACHE)
rb_define_method(rb_cIO, "directio?", io_get_directio, 0);
rb_define_method(rb_cIO, "directio=", io_set_directio, 1);

Expand Down

0 comments on commit 72d0710

Please sign in to comment.