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

Method closeMapping

Engine/MemoryFile.cpp:333–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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