From f179b4c117ffc1886cf106c053b248ad3f88a968 Mon Sep 17 00:00:00 2001 From: Anton Kovalenko Date: Tue, 29 Mar 2011 15:55:42 +0400 Subject: [PATCH] sb-simple-streams: use the Windows file mapping API for memory-mapped files Thanks to Anton Kovalenko. --- contrib/sb-simple-streams/file.lisp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/contrib/sb-simple-streams/file.lisp b/contrib/sb-simple-streams/file.lisp index 01da23b..e668269 100644 --- a/contrib/sb-simple-streams/file.lisp +++ b/contrib/sb-simple-streams/file.lisp @@ -222,9 +222,20 @@ (warn "Unable to memory-map entire file.") (setf size (1- most-positive-fixnum))) (let ((buffer + #-win32 (handler-case - (sb-posix:mmap nil size prot sb-posix::MAP-SHARED fd 0) - (sb-posix:syscall-error nil)))) + (sb-posix:mmap nil size prot sb-posix::MAP-SHARED fd 0) + (sb-posix:syscall-error nil)) + #+win32 + (let ((mapping + (sb-win32:create-file-mapping + (sb-win32:get-osfhandle fd) nil 2 0 size nil))) + (typecase mapping + ((integer -1 0) nil) + (t (let ((sap (prog1 (sb-win32:map-view-of-file + mapping 4 0 0 size) + (sb-win32:close-handle mapping)))) + (and (not (zerop (sb-sys:sap-int sap))) sap))))))) (when (null buffer) (sb-unix:unix-close fd) (sb-ext:cancel-finalization stream) @@ -244,7 +255,8 @@ (melding-stream stream) efmt 'mapped)) (sb-ext:finalize stream (lambda () - (sb-posix:munmap buffer size) + #+win32 (sb-win32:unmap-view-of-file buffer) + #-win32 (sb-posix:munmap buffer size) (format *terminal-io* "~&;;; ** unmapped ~S" buffer)) :dont-save t)))) stream))) @@ -253,7 +265,8 @@ (defmethod device-close ((stream mapped-file-simple-stream) abort) (with-stream-class (mapped-file-simple-stream stream) (when (sm buffer stream) - (sb-posix:munmap (sm buffer stream) (sm buf-len stream)) + #+win32 (sb-win32:unmap-view-of-file (sm buffer stream)) + #-win32 (sb-posix:munmap (sm buffer stream) (sm buf-len stream)) (setf (sm buffer stream) nil)) (sb-unix:unix-close (or (sm input-handle stream) (sm output-handle stream)))) t) -- 1.7.10.4