本文整理汇总了C++中shm_unlink函数的典型用法代码示例。如果您正苦于以下问题:C++ shm_unlink函数的具体用法?C++ shm_unlink怎么用?C++ shm_unlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shm_unlink函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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]);
}
}
示例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;
}
示例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
}
示例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;
}
示例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
}
示例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;
}
示例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;
}
}
示例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;
}