diff --git a/include/villas/nodes/shmem.h b/include/villas/nodes/shmem.h index 56d0d6cf4..791e4b6ba 100644 --- a/include/villas/nodes/shmem.h +++ b/include/villas/nodes/shmem.h @@ -40,11 +40,10 @@ * @see node_type */ struct shmem { - const char* name; /**< Name of the shm object. */ + const char* name; /**< Name of the shm object. */ struct shmem_conf conf; /**< Interface configuration struct. */ - char **exec; /**< External program to execute on start. */ - - struct shmem_int intf; /**< Shmem interface */ + char **exec; /**< External program to execute on start. */ + struct shmem_int intf; /**< Shmem interface */ }; /** @see node_type::print */ diff --git a/lib/nodes/shmem.c b/lib/nodes/shmem.c index d1338cc7c..306902f0c 100644 --- a/lib/nodes/shmem.c +++ b/lib/nodes/shmem.c @@ -83,6 +83,7 @@ int shmem_open(struct node *n) if (!ret) serror("Failed to spawn external program"); } + ret = shmem_int_open(shm->name, &shm->intf, &shm->conf); if (ret < 0) serror("Opening shared memory interface failed"); diff --git a/lib/shmem.c b/lib/shmem.c index d192ee05e..45c443990 100644 --- a/lib/shmem.c +++ b/lib/shmem.c @@ -68,6 +68,7 @@ int shmem_int_open(const char *name, struct shmem_int* shm, struct shmem_conf* c fd = shm_open(name, O_RDWR, 0); if (fd < 0) return -1; + /* Theoretically, the other process might have created the object, but * isn't done with initializing it yet. So in the creating process, * we only reserve a small amount of memory, just enough for the barrier, @@ -80,8 +81,8 @@ int shmem_int_open(const char *name, struct shmem_int* shm, struct shmem_conf* c if (stat.st_size > SHMEM_MIN_SIZE) break; } - len = stat.st_size; + len = stat.st_size; base = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (base == MAP_FAILED) return -1; @@ -92,6 +93,7 @@ int shmem_int_open(const char *name, struct shmem_int* shm, struct shmem_conf* c shared = (struct shmem_shared *) cptr; pthread_barrier_wait(&shared->start_bar); + shm->base = base; shm->shared = shared; shm->len = 0; @@ -154,11 +156,14 @@ int shmem_int_open(const char *name, struct shmem_int* shm, struct shmem_conf* c errno = ENOMEM; return -1; } + shm->base = base; shm->len = len; shm->shared = shared; shm->secondary = 0; + pthread_barrier_wait(&shared->start_bar); + return 1; }