static void THRefcountedMapAllocator_free(void* ctx_, void* data) { THMapAllocatorContext *ctx = ctx_; #ifdef _WIN32 THMapInfo *info = (THMapInfo*)(((char*)data) - TH_ALLOC_ALIGNMENT); if (THAtomicDecrementRef(&info->refcount)) { CloseHandle(ctx->handle); } if(UnmapViewOfFile(data) == 0) THError("could not unmap the shared memory file"); #else /* _WIN32 */ THMapInfo *info = (THMapInfo*)(((char*)data) - TH_ALLOC_ALIGNMENT); if (THAtomicDecrementRef(&info->refcount)) { #ifdef HAVE_SHM_UNLINK if (shm_unlink(ctx->filename) == -1) THError("could not unlink the shared memory file %s", ctx->filename); #else THError("could not unlink the shared memory file %s, shm_unlink not available on platform", ctx->filename); #endif /* HAVE_SHM_UNLINK */ } if (munmap(info, ctx->size)) THError("could not unmap the shared memory file %s", ctx->filename); #endif /* _WIN32 */ THMapAllocatorContext_free(ctx); }
static void THMapAllocator_free(void* ctx_, void* data) { THMapAllocatorContext *ctx = ctx_; #ifdef _WIN32 if(UnmapViewOfFile(data) == 0) THError("could not unmap the shared memory file"); #else /* _WIN32 */ if (ctx->flags & TH_ALLOCATOR_MAPPED_KEEPFD) { if (close(ctx->fd) == -1) THError("could not close file descriptor %d", ctx->fd); } if (munmap(data, ctx->size)) THError("could not unmap the shared memory file"); if (!(ctx->flags & (TH_ALLOCATOR_MAPPED_FROMFD | TH_ALLOCATOR_MAPPED_UNLINK))) { if (ctx->flags & TH_ALLOCATOR_MAPPED_SHAREDMEM) { #ifdef HAVE_SHM_UNLINK if (shm_unlink(ctx->filename) == -1) THError("could not unlink the shared memory file %s", ctx->filename); #else THError("could not unlink the shared memory file %s, shm_unlink not available on platform", ctx->filename); #endif } } #endif /* _WIN32 */ THMapAllocatorContext_free(ctx); }