Commit 372edc9b authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Improve sample function a bit

parent 7c27331c
......@@ -296,13 +296,14 @@ int controller_block_sample_init(void)
"Block %s has a calculate function",
blocks[i]->name);
tmp = realloc(calculates,
sizeof(struct calculate_func) * (nr_calculates+1));
sizeof(struct calculate_func) * (nr_calculates+2));
if (tmp) {
calculates = tmp;
calculates[nr_calculates].func =
blocks[i]->calculate;
calculates[nr_calculates].block = blocks[i];
nr_calculates++;
calculates[nr_calculates].block = NULL;
} else {
log_send(LOG_T_ERROR,
"Out of memory allocating memory");
......@@ -483,10 +484,17 @@ uint32_t controller_samplenr = 0;
void controller_block_calculate(void)
{
int i;
struct calculate_func *calculate;
struct controller_block *block;
calculate = calculates;
for (i = 0; i < nr_calculates; i++)
calculates[i].func(calculates[i].block);
for (calculate = calculates; true; calculate++) {
block = calculate->block;
if (!block)
return;
calculate->func(block);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment