MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / sharedMemoryOpen

Function sharedMemoryOpen

Common/helper_multiprocess.cpp:71–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71int sharedMemoryOpen(const char *name, size_t sz, sharedMemoryInfo *info) {
72#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
73 info->size = sz;
74
75 info->shmHandle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name);
76 if (info->shmHandle == 0) {
77 return GetLastError();
78 }
79
80 info->addr = MapViewOfFile(info->shmHandle, FILE_MAP_ALL_ACCESS, 0, 0, sz);
81 if (info->addr == NULL) {
82 return GetLastError();
83 }
84
85 return 0;
86#else
87 info->size = sz;
88
89 info->shmFd = shm_open(name, O_RDWR, 0777);
90 if (info->shmFd < 0) {
91 return errno;
92 }
93
94 info->addr = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, info->shmFd, 0);
95 if (info->addr == NULL) {
96 return errno;
97 }
98
99 return 0;
100#endif
101}
102
103void sharedMemoryClose(sharedMemoryInfo *info) {
104#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)

Callers 1

childProcessFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected