From cf088abef1ac4c55db9e6962ddac416463c14125 Mon Sep 17 00:00:00 2001 From: Mark Shinwell Date: Thu, 1 Apr 2010 07:36:49 +0000 Subject: release runtime lock for lseek (mantis 4801) git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10223 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- otherlibs/unix/lseek.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'otherlibs/unix/lseek.c') diff --git a/otherlibs/unix/lseek.c b/otherlibs/unix/lseek.c index 6dece9503..cb59bb551 100644 --- a/otherlibs/unix/lseek.c +++ b/otherlibs/unix/lseek.c @@ -39,8 +39,10 @@ static int seek_command_table[] = { CAMLprim value unix_lseek(value fd, value ofs, value cmd) { file_offset ret; + caml_enter_blocking_section(); ret = lseek(Int_val(fd), Long_val(ofs), seek_command_table[Int_val(cmd)]); + caml_leave_blocking_section(); if (ret == -1) uerror("lseek", Nothing); if (ret > Max_long) unix_error(EOVERFLOW, "lseek", Nothing); return Val_long(ret); @@ -49,8 +51,13 @@ CAMLprim value unix_lseek(value fd, value ofs, value cmd) CAMLprim value unix_lseek_64(value fd, value ofs, value cmd) { file_offset ret; - ret = lseek(Int_val(fd), File_offset_val(ofs), - seek_command_table[Int_val(cmd)]); + /* [ofs] is an Int64, which is stored as a custom block; we must therefore + extract its contents before dropping the runtime lock, or it might be + moved. */ + file_offset ofs_c = File_offset_val(ofs); + caml_enter_blocking_section(); + ret = lseek(Int_val(fd), ofs_c, seek_command_table[Int_val(cmd)]); + caml_leave_blocking_section(); if (ret == -1) uerror("lseek", Nothing); return Val_file_offset(ret); } -- cgit v1.2.3-70-g09d2