| 48 | }; |
| 49 | |
| 50 | void shared_open(SharedData* data, const char* name, size_t nbytes) |
| 51 | { |
| 52 | int d = shm_open(name, O_RDWR, S_IRUSR | S_IWUSR); |
| 53 | if (d != -1) { |
| 54 | void* bytes = mmap(NULL, nbytes, PROT_READ | PROT_WRITE, MAP_SHARED, d, 0); |
| 55 | data->name = name; |
| 56 | data->descriptor = d; |
| 57 | data->bytes = bytes; |
| 58 | data->nbytes = nbytes; |
| 59 | } else { |
| 60 | if (errno != ENOENT) { |
| 61 | // don't print if shm can not be found because we want to loop over from |
| 62 | // caller again until the other ranks created the shm |
| 63 | printf("shared_open %s failed, errno=%d\n", name, errno); |
| 64 | } |
| 65 | data->descriptor = -1; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void shared_create(SharedData* data, const char* name, void* bytes, size_t nbytes) |
| 70 | { |
no outgoing calls
no test coverage detected