MCPcopy Create free account
hub / github.com/MrKepzie/Natron / closeMapping

Method closeMapping

Engine/MemoryFile.cpp:332–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330}
331
332void
333MemoryFilePrivate::closeMapping(bool drop_pages)
334{
335#if defined(__NATRON_UNIX__)
336 if (drop_pages) {
337 int rc;
338#ifdef MS_KILLPAGES
339 // Mac OS X always returns an error with MADV_FREE,
340 // so we'll use msync(MS_KILLPAGES) instead.
341 rc = msync(data, size, MS_KILLPAGES);
342 //if( rc ) return ERR_MEM_STR_NUM("drop_pages(MS_KILLPAGES) failed", rc);
343#else
344# ifdef MADV_FREE
345 rc = madvise(data, size, MADV_FREE);
346 //if( rc ) return ERR_MEM_STR_NUM("drop_pages(MADV_FREE) failed", rc);
347# else
348# ifdef POSIX_MADV_DONTNEED
349 // we just hope that DONTNEED will actually free
350 // the pages...
351 rc = posix_madvise(data, size, POSIX_MADV_DONTNEED);
352 //if( rc ) return ERR_MEM_STR_NUM("drop_pages(POSIX_MADV_DONTNEED) failed", rc);
353# else
354 rc = madvise(data, size, MADV_DONTNEED);
355 //if( rc ) return ERR_MEM_STR_NUM("drop_pages(MADV_DONTNEED) failed", rc);
356 // end if POSIX_MADV_DONTNEED
357# endif
358 // end if MADV_FREE
359# endif
360 // end if MS_KILLPAGES
361#endif
362 Q_UNUSED(rc);
363 }
364 if (::munmap(data, size) != 0) {
365 std::stringstream ss;
366 ss << "MemoryFile EXC : Failed to unmap \"" << path << "\": " << std::strerror(errno) << " (" << errno << ")";
367 throw std::runtime_error( ss.str() );
368 }
369 ::close(file_handle);
370#elif defined(__NATRON_WIN32__)
371 Q_UNUSED(drop_pages);
372 if (::UnmapViewOfFile(data) == 0) {
373 throw std::runtime_error("Failed to unmap the mapped file");
374 }
375 ::CloseHandle(file_mapping_handle);
376 ::CloseHandle(file_handle);
377#endif
378}
379
380bool
381MemoryFile::flush(FlushTypeEnum type, void* data, std::size_t size)

Callers 2

~MemoryFileMethod · 0.80
removeMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected