• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ shm_unlink函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中shm_unlink函数的典型用法代码示例。如果您正苦于以下问题:C++ shm_unlink函数的具体用法?C++ shm_unlink怎么用?C++ shm_unlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了shm_unlink函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: sock_av_close

static int sock_av_close(struct fid *fid)
{
    struct sock_av *av;
    int ret = 0;
    av = container_of(fid, struct sock_av, av_fid.fid);
    if (atomic_get(&av->ref))
        return -FI_EBUSY;

    if (!av->name)
        free(av->table_hdr);
    else {
        shm_unlink(av->name);
        free(av->name);
        ret = munmap(av->table_hdr, SOCK_AV_TABLE_SZ(av->attr.count, av->name));
        if (ret)
            SOCK_LOG_ERROR("munmap failed: %s\n", strerror(errno));
        close(av->shared_fd);
    }

    atomic_dec(&av->domain->ref);
    free(av);
    return 0;
}
开发者ID:chuckfossen,项目名称:libfabric-cray,代码行数:23,代码来源:sock_av.c


示例2: main

int
main(int argc, char **argv)
{
	int		fd;
	struct shmstruct	*ptr;

	if (argc != 3)
		err_quit("usage: server1 <shmname> <semname>");

	shm_unlink(Px_ipc_name(argv[1]));		/* OK if this fails */
		/* 4create shm, set its size, map it, close descriptor */
	fd = Shm_open(Px_ipc_name(argv[1]), O_RDWR | O_CREAT | O_EXCL, FILE_MODE);
	Ftruncate(fd, sizeof(struct shmstruct));
	ptr = Mmap(NULL, sizeof(struct shmstruct), PROT_READ | PROT_WRITE,
			   MAP_SHARED, fd, 0);
	Close(fd);

	sem_unlink(Px_ipc_name(argv[2]));		/* OK if this fails */
	mutex = Sem_open(Px_ipc_name(argv[2]), O_CREAT | O_EXCL, FILE_MODE, 1);
	Sem_close(mutex);

	exit(0);
}
开发者ID:piaoyimq,项目名称:CppSpace,代码行数:23,代码来源:server1.c


示例3: getpid

int FileLib::createUnnamedSharedMemoryTemp(void) {
	int shmfd = -1;
	char tmpfn[1024];
	pid_t pid = getpid();

	do {
		snprintf(tmpfn, sizeof(tmpfn), "/.%d_tmp_%d", pid, rand());

		errno = 0;
		shmfd = shm_open(tmpfn, O_RDWR | O_CREAT | O_EXCL, 0400);
		if (-1 == shmfd) {
			if (errno != EEXIST) {
				break;
			}
		} else {
			
			shm_unlink(tmpfn);
			break;
		}
	} while (true);

	return shmfd;
}
开发者ID:Applied-Duality,项目名称:griddb_nosql,代码行数:23,代码来源:os.cpp


示例4: destroy

void destroy()
{
	mysql_library_end();

	int r = munmap(pIdentityTag, region_size);
	if (r != 0)
	{
		syslog(LOG_ERR, "munmap failed");
	}

	  r = shm_unlink(shared_memory_name);
	  if (r != 0)
	  {
		  syslog(LOG_ERR, "shm_unlink failed");
	  }


	config_destroy(&config);

	syslog (LOG_INFO, "Terminating");

	closelog();
}
开发者ID:binaryfrost,项目名称:equinox,代码行数:23,代码来源:zenith.c


示例5: THRefcountedMapAllocator_free

static void THRefcountedMapAllocator_free(void* ctx_, void* data) {
  THMapAllocatorContext *ctx = ctx_;

#ifdef _WIN32
  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);
}
开发者ID:jacklicn,项目名称:torch7,代码行数:23,代码来源:THAllocator.c


示例6: os_posix_sharedMemoryDestroy

/** \brief Destroy the POSIX shared memory object related to name
 *
 * First \b os_posix_sharedMemoryDestroy finds the shared object identifier
 * related to \b name by calling \b os_posix_getShmObjName. If the identifier is
 * found, the shared object is detroyed by calling \b shm_unlink.
 * After that the key file related to name is detroyed by calling
 * \b os_posix_destroyKeyFile.
 */
os_result
os_posix_sharedMemoryDestroy (
    const char *name)
{
    char *shmname;
    os_result rv = os_resultSuccess;

    assert (name != NULL);
    shmname = os_posix_getShmObjName (name, NULL, 0);
    if (shmname != NULL) {
        if (shm_unlink (shmname) == -1) {
            OS_REPORT (OS_WARNING, "os_posix_sharedMemoryDestroy", 1,
                "shm_unlink failed with error %d (%s)", os_getErrno(), name);
            rv = os_resultFail;
        }
        if (os_posix_destroyKeyFile (name) == -1) {
            rv = os_resultFail;
        }
        os_free (shmname);
    }
    
    return rv;
}
开发者ID:osrf,项目名称:opensplice,代码行数:31,代码来源:os_sharedmem_file.c


示例7: ipc_destroy

void ipc_destroy(ipc_t conn, int owner) {

    if (conn == NULL) {
        return;
    }

    // It goes without saying that the order of these calls is important
    sem_close(conn->lock);

    if (owner) {
        ipc_sem_destroy(conn->queue->readWait);
        ipc_sem_destroy(conn->queue->writeSem);
    }

    munmap(conn->queue, SHMEM_SIZE);

    if (owner) {
        shm_unlink(conn->name);
        sem_unlink(conn->name);
    }

    free(conn);
}
开发者ID:acrespo,项目名称:TP1-SO-2c2011,代码行数:23,代码来源:shmem.c


示例8: main

int main(int argc,char **argv)
{
    int shm_id;
    char *ptr;
    sem_t *sem;
    
    if(argc!=2)
    {
        printf("usage:shm_open<pathname>\n");
        exit(1);
    }
    shm_id=shm_open(argv[1],O_RDWR|O_CREAT,0644);
    ftruncate(shm_id,100);
    sem=sem_open(argv[1],O_CREAT,0644,1);
    ptr=mmap(NULL,100,PROT_READ|PROT_WRITE,MAP_SHARED,shm_id,0);
    strcpy(ptr,"\0");
    while(1)
    {
        if((strcmp(ptr,"\0"))==0)
        {
           continue;
        }
        else
        {
            if((strcmp(ptr,"q\n"))==0)
             {
                 break;
             }
             sem_wait(sem);
             printf("server:%s",ptr);
             strcpy(ptr,"\0");
             sem_post(sem);
        }
        sem_unlink(argv[1]);
        shm_unlink(argv[1]);
    }
}
开发者ID:liuwenhui2365,项目名称:Programs_thread,代码行数:37,代码来源:pthread36.c


示例9: main

int main(int argc, char *argv[])
{
	int r;
	const char *memname = "/mymem";
	const size_t region_size = 1024;
	/* 打开共享内存文件 */
	int fd = shm_open(memname, O_CREAT | O_TRUNC | O_RDWR, 0666);
	if (fd == -1) error_out("shm_open");
	/* 将文件截取至指定的大小 */
	r = ftruncate(fd, region_size);
	if (r != 0) error_out("ftruncate");
	/* 将文件映射为内存 */
	void *ptr = mmap(0, region_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (ptr == MAP_FAILED) error_out("mmap");
	/* 关闭文件 */
	close(fd);
	/* 产生新进程 */
	pid_t pid = fork();
	if (pid == 0) {
		/* 子进程向共享内存写入数据 */
		unsigned long *d = (unsigned long *) ptr;
		*d = 0xdeadbeef;
		exit(0);
	} else {
		/* 父进程等待子进程结束并读共享内存 */
		int status;
		waitpid(pid, &status, 0);
		printf("The data child wrote is %#lx\n", *(unsigned long *)ptr);
	}
	/* 取消内存映射 */
	r = munmap(ptr, region_size);
	if (r != 0) error_out("munmap");
	/* 删除共享内存文件 */
	r = shm_unlink(memname);
	if (r != 0) error_out("shm_unlink");
	return 0;
}
开发者ID:tmhm,项目名称:Qt4_Desktop,代码行数:37,代码来源:pmem.c


示例10: CreateFileMapping

void MemArena::GrabLowMemSpace(size_t size)
{
#ifdef _WIN32
    hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, (DWORD)(size), nullptr);
    GetSystemInfo(&sysInfo);
#elif defined(ANDROID)
    // Use ashmem so we don't have to allocate a file on disk!
    fd = ashmem_create_region("PPSSPP_RAM", size);
    // Note that it appears that ashmem is pinned by default, so no need to pin.
    if (fd < 0)
    {
        LOG_ERROR(Common_Memory, "Failed to grab ashmem space of size: %08x  errno: %d", (int)size, (int)(errno));
        return;
    }
#else
    // Try to find a non-existing filename for our shared memory.
    // In most cases the first one will be available, but it's nicer to search
    // a bit more.
    for (int i = 0; i < 10000; i++)
    {
        std::string file_name = Common::StringFromFormat("/citramem.%d", i);
        fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
        if (fd != -1)
        {
            shm_unlink(file_name.c_str());
            break;
        }
        else if (errno != EEXIST)
        {
            LOG_ERROR(Common_Memory, "shm_open failed: %s", strerror(errno));
            return;
        }
    }
    if (ftruncate(fd, size) < 0)
        LOG_ERROR(Common_Memory, "Failed to allocate low memory space");
#endif
}
开发者ID:Penguinwizzard,项目名称:citra,代码行数:37,代码来源:mem_arena.cpp


示例11: DRIFreePixmapImp

static Bool
DRIFreePixmapImp(DrawablePtr pDrawable) {
    DRIPixmapBufferPtr shared;
    PixmapPtr pPix;

    if(pDrawable->type != DRAWABLE_PIXMAP)
	return FALSE;

    pPix = (PixmapPtr)pDrawable;

    shared = dixLookupPrivate(&pPix->devPrivates, DRIPixmapBufferPrivKey);

    if(NULL == shared)
	return FALSE;

    close(shared->fd);
    munmap(shared->buffer, shared->length);
    shm_unlink(shared->shmPath);
    xfree(shared);

    dixSetPrivate(&pPix->devPrivates, DRIPixmapBufferPrivKey, (pointer)NULL);

    return TRUE;
}
开发者ID:L3oV1nc3,项目名称:VMGL,代码行数:24,代码来源:dri.c


示例12: release_shmem_resources

/**
 * @brief Cleanup shared memory resources.
 *
 * @param[in] ni
 */
static void release_shmem_resources(ni_t *ni)
{
    pool_fini(&ni->sbuf_pool);

    if (ni->shmem.comm_pad != MAP_FAILED) {
        munmap(ni->shmem.comm_pad, ni->shmem.comm_pad_size);
        ni->shmem.comm_pad = MAP_FAILED;
    }

    if (ni->shmem.comm_pad_shm_name) {
        /* Destroy the mmaped file so it doesn't pollute.
         * All ranks try it in case rank 0 died. */
        shm_unlink(ni->shmem.comm_pad_shm_name);

        free(ni->shmem.comm_pad_shm_name);
        ni->shmem.comm_pad_shm_name = NULL;
    }

    knem_fini(ni);

#if !USE_KNEM
    PTL_FASTLOCK_DESTROY(&ni->shmem.noknem_lock);
#endif
}
开发者ID:foool,项目名称:portals4,代码行数:29,代码来源:ptl_shmem.c


示例13: _posixshmem_shm_unlink_impl

static PyObject *
_posixshmem_shm_unlink_impl(PyObject *module, PyObject *path)
/*[clinic end generated code: output=42f8b23d134b9ff5 input=8dc0f87143e3b300]*/
{
    int rv;
    int async_err = 0;
    const char *name = PyUnicode_AsUTF8(path);
    if (name == NULL) {
        return NULL;
    }
    do {
        Py_BEGIN_ALLOW_THREADS
        rv = shm_unlink(name);
        Py_END_ALLOW_THREADS
    } while (rv < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));

    if (rv < 0) {
        if (!async_err)
            PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path);
        return NULL;
    }

    Py_RETURN_NONE;
}
开发者ID:Eyepea,项目名称:cpython,代码行数:24,代码来源:posixshmem.c


示例14: cleanup

static void cleanup(void)
{
    if (tmpshmem) {
        munmap(tmpshmem, TMPSHMSIZE);
        tmpshmem = NULL;
    }

    if (tmpshm) {
        shm_unlink(tmpshm);
        g_free(tmpshm);
        tmpshm = NULL;
    }

    if (tmpserver) {
        g_unlink(tmpserver);
        g_free(tmpserver);
        tmpserver = NULL;
    }

    if (tmpdir) {
        g_rmdir(tmpdir);
        tmpdir = NULL;
    }
}
开发者ID:gkurz,项目名称:qemu,代码行数:24,代码来源:ivshmem-test.c


示例15: main

int main() {
	int fd, result;

	result = shm_unlink(SHM_NAME);
	if (result != 0 && errno != ENOENT) {
		/* The shared memory object exist and shm_unlink can not
		   remove it. */
		perror("An error occurs when calling shm_unlink()");
		return PTS_UNRESOLVED;
	}

	fd = shm_open(SHM_NAME, O_RDONLY, S_IRUSR);

	if (fd == -1 && errno == ENOENT) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if (fd != -1) {
		printf("shm_open() success.\n");
		return PTS_FAIL;
	}

	perror("Unexpected error");
	return PTS_FAIL;
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:24,代码来源:41-1.c


示例16: THMapAllocator_free

static void THMapAllocator_free(void* ctx_, void* data) {
  if (data == NULL)
    return;

  THMapAllocatorContext *ctx = ctx_;

#ifdef _WIN32
  if ((ctx->flags & TH_ALLOCATOR_MAPPED_KEEPFD) || (ctx->flags & TH_ALLOCATOR_MAPPED_SHAREDMEM))
    CloseHandle(ctx->handle);
  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);
}
开发者ID:Northrend,项目名称:pytorch,代码行数:36,代码来源:THAllocator.c


示例17: release_shared_mem

int release_shared_mem(const char *name, int shm, int *mem_ptr, int size)
{
    int res = munmap(mem_ptr, size);
    if (res)
    {
        perror("release_shared_mem (munmap)");
        return res;
    }
    res = close(shm);
    if (res)
    {
        perror("release_shared_mem (close)");
        return res;
    }
    res = shm_unlink(name);
    if (res)
    {
        perror("release_shared_mem (shm_unlink)");
        return res;
    }

    printf("released shared memory %s, size = %d\n", name, size);
    return res;
}
开发者ID:kinpa200296,项目名称:OSaE_labs,代码行数:24,代码来源:common.c


示例18: main

	int
main(int argc, char **argv)
{
	int		fd1, fd2, *ptr1, *ptr2;
	pid_t	childpid;
	struct stat	stat;

	if (argc != 2)
		handle_error("usage: test3 <name>");

	shm_unlink(argv[1]);
	fd1 = shm_open(argv[1], O_RDWR | O_CREAT | O_EXCL, 0666);
	ftruncate(fd1, sizeof(int));
	fd2 = open("/etc/motd", O_RDONLY);
	fstat(fd2, &stat);

	if ( (childpid = fork()) == 0) {
		/* 4child */
		ptr2 = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd2, 0);
		ptr1 = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE,
				MAP_SHARED, fd1, 0);
		printf("child: shm ptr = %p, motd ptr = %p\n", ptr1, ptr2);

		sleep(5);
		printf("shared memory integer = %d\n", *ptr1);
		exit(0);
	}
	/* 4parent: mmap in reverse order from child */
	ptr1 = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd1, 0);
	ptr2 = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd2, 0);
	printf("parent: shm ptr = %p, motd ptr = %p\n", ptr1, ptr2);
	*ptr1 = 777;
	waitpid(childpid, NULL, 0);

	exit(0);
}
开发者ID:hzsunzixiang,项目名称:programming,代码行数:36,代码来源:test3.c


示例19: SBCELT_Init

int SBCELT_Init() {
	char shmfn[50];
	if (snprintf(&shmfn[0], 50, "/sbcelt-%lu", (unsigned long) getpid()) < 0) {
		return -1;
	}

	shm_unlink(&shmfn[0]);
	int fd = shm_open(&shmfn[0], O_CREAT|O_RDWR, 0600);
	if (fd == -1) {
		return -1;
	} else {
		if (ftruncate(fd, SBCELT_PAGES*SBCELT_PAGE_SIZE) == -1) {
			debugf("unable to truncate: %s (%i)", strerror(errno), errno);
			return -1;
		}

		void *addr = mmap(NULL, SBCELT_PAGES*SBCELT_PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, 0);
		if (addr == MAP_FAILED) {
			debugf("unable to mmap: %s (%i)", strerror(errno), errno);
			return -1;
		}
		memset(addr, 0, SBCELT_PAGES*SBCELT_PAGE_SIZE);

		workpage = addr;
		decpage = addr+SBCELT_PAGE_SIZE;

		workpage->busywait = sysconf(_SC_NPROCESSORS_ONLN) > 0;

		int i;
		for (i = 0; i < SBCELT_SLOTS; i++) {
			decpage->slots[i].available = 1;
		}
	}

	return 0;
}
开发者ID:chiefdome,项目名称:sbcelt,代码行数:36,代码来源:libsbcelt.c


示例20: test_read_write

void test_read_write(bool write) {
  int MEMSIZE = 10000;

  int fd;
  if (write) {
    fd = shm_open(MEMNAME, O_RDWR | O_CREAT | O_EXCL, (mode_t)0666);
  } else {
    fd = shm_open(MEMNAME, O_RDWR | O_CREAT | O_EXCL, (mode_t)0666);
  }

  if (fd == -1) {
    perror("shm_open1");
    return;
  }

  // if (write) {
  int res = ftruncate(fd, MEMSIZE);
  if (res == -1) {
    perror("TRUNC");
    return;
  }
  printf("NEW: mem truncated:%u bytes\n", MEMSIZE);
  // }

  int* map = (int*)mmap(NULL, MEMSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (write) {
    map[0] = 22;
    map[1] = 33;
    map[2] = 44;
  }

  std::cout << map[0] << map[1] << map[2] << std::endl;

  munmap(map, MEMSIZE);
  shm_unlink(MEMNAME);
}
开发者ID:kzub,项目名称:deals-server,代码行数:36,代码来源:shr_mem_test2.cpp



注:本文中的shm_unlink函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ shm_unlock函数代码示例发布时间:2022-05-30
下一篇:
C++ shm_open函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap