1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

node: clone samples if modified by write hooks

This commit is contained in:
Steffen Vogel 2021-06-19 12:52:58 -04:00
parent 5a64f25b67
commit ba72f5cc27
5 changed files with 23 additions and 11 deletions

View file

@ -65,7 +65,7 @@ int hook_list_prepare_signals(struct vlist *hs, struct vlist *signals);
int hook_list_add(struct vlist *hs, int mask, struct vpath *p, struct vnode *n);
int hook_list_process(struct vlist *hs, struct sample * smps[], unsigned cnt);
int hook_list_process(struct vlist *hs, struct sample * smps[], unsigned cnt, bool clone_if_modified = false);
void hook_list_periodic(struct vlist *hs);

View file

@ -200,7 +200,7 @@ int node_reverse(struct vnode *n);
int node_read(struct vnode *n, struct sample * smps[], unsigned cnt);
int node_write(struct vnode *n, struct sample * smps[], unsigned cnt);
int node_write(struct vnode *n, struct sample * smps[], unsigned cnt, bool clone_if_modified = false);
int node_poll_fds(struct vnode *n, int fds[]);

View file

@ -135,18 +135,27 @@ void hook_list_prepare(struct vlist *hs, vlist *sigs, int m, struct vpath *p, st
}
}
int hook_list_process(struct vlist *hs, struct sample * smps[], unsigned cnt)
int hook_list_process(struct vlist *hs, struct sample *smps[], unsigned cnt, bool clone_if_modified)
{
unsigned current, processed = 0;
unsigned processed = 0;
if (vlist_length(hs) == 0)
return cnt;
for (current = 0; current < cnt; current++) {
struct sample *smp = smps[current];
for (unsigned i = 0; i < cnt; i++) {
struct sample *smp, *old_smp;
for (size_t i = 0; i < vlist_length(hs); i++) {
Hook *h = (Hook *) vlist_at(hs, i);
if (clone_if_modified) {
old_smp = smps[i];
smps[i] = sample_clone(old_smp);
sample_decref(old_smp);
}
smp = smps[i];
for (size_t j = 0; j < vlist_length(hs); j++) {
Hook *h = (Hook *) vlist_at(hs, j);
auto ret = h->process(smp);
smp->signals = h->getSignals();
@ -165,7 +174,7 @@ int hook_list_process(struct vlist *hs, struct sample * smps[], unsigned cnt)
}
}
stop: SWAP(smps[processed], smps[current]);
stop: SWAP(smps[processed], smps[i]);
processed++;
skip: {}
}

View file

@ -494,7 +494,7 @@ int node_read(struct vnode *n, struct sample * smps[], unsigned cnt)
#endif /* WITH_HOOKS */
}
int node_write(struct vnode *n, struct sample * smps[], unsigned cnt)
int node_write(struct vnode *n, struct sample * smps[], unsigned cnt, bool clone_if_modified)
{
int tosend, sent, nsent = 0;
unsigned vect;
@ -508,7 +508,7 @@ int node_write(struct vnode *n, struct sample * smps[], unsigned cnt)
#ifdef WITH_HOOKS
/* Run write hooks */
cnt = hook_list_process(&n->out.hooks, smps, cnt);
cnt = hook_list_process(&n->out.hooks, smps, cnt, clone_if_modified && !n->out.read_only_hooks);
if (cnt <= 0)
return cnt;
#endif /* WITH_HOOKS */

View file

@ -42,6 +42,8 @@ int node_direction_prepare(struct vnode_direction *nd, struct vnode *n)
int m = nd->builtin ? t | (int) Hook::Flags::BUILTIN : 0;
hook_list_prepare(&nd->hooks, &nd->signals, m, nullptr, n);
nd->read_only_hooks = hook_list_is_read_only(&nd->hooks);
#endif /* WITH_HOOKS */
nd->state = State::PREPARED;
@ -58,6 +60,7 @@ int node_direction_init(struct vnode_direction *nd, enum NodeDir dir, struct vno
nd->vectorize = 1;
nd->builtin = 1;
nd->path = nullptr;
nd->read_only_hooks = false;
#ifdef WITH_HOOKS
ret = hook_list_init(&nd->hooks);