mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
shm node: use pthread_barrier for synchronizing the start
This commit is contained in:
parent
385efa1313
commit
c135451db7
3 changed files with 11 additions and 1 deletions
|
@ -19,6 +19,8 @@ struct shmem_shared {
|
|||
union shmem_queue out; /**< Queue for samples passed from node to external program.*/
|
||||
int cond_out; /**< Whether to use a pthread_cond_t to signal if new samples are written to outqueue. */
|
||||
struct pool pool; /**< Pool for the samples in the queues. */
|
||||
pthread_barrier_t start_bar;
|
||||
pthread_barrierattr_t start_attr;
|
||||
atomic_size_t node_stopped;
|
||||
atomic_size_t ext_stopped;
|
||||
};
|
||||
|
|
|
@ -89,8 +89,14 @@ int shmem_open(struct node *n) {
|
|||
if (pool_init(&shm->shared->pool, shm->insize+shm->outsize, SAMPLE_LEN(shm->sample_size), shm->manager) < 0)
|
||||
error("Shm pool allocation failed (not enough memory?)");
|
||||
|
||||
pthread_barrierattr_init(&shm->shared->start_attr);
|
||||
pthread_barrierattr_setpshared(&shm->shared->start_attr, PTHREAD_PROCESS_SHARED);
|
||||
pthread_barrier_init(&shm->shared->start_bar, &shm->shared->start_attr, 2);
|
||||
|
||||
if (shm->exec && !spawn(shm->exec[0], shm->exec))
|
||||
serror("Failed to spawn external program");
|
||||
|
||||
pthread_barrier_wait(&shm->shared->start_bar);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,9 @@ struct shmem_shared* shmem_shared_open(const char *name, void **base_ptr)
|
|||
cptr = (char *) base + sizeof(struct memtype) + sizeof(struct memblock);
|
||||
if (base_ptr)
|
||||
*base_ptr = base;
|
||||
return (struct shmem_shared *) cptr;
|
||||
shm = (struct shmem_shared *) cptr;
|
||||
pthread_barrier_wait(&shm->start_bar);
|
||||
return shm;
|
||||
}
|
||||
|
||||
int shmem_shared_close(struct shmem_shared *shm, void *base)
|
||||
|
|
Loading…
Add table
Reference in a new issue