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

added sample_{alloc,free}

This commit is contained in:
Steffen Vogel 2016-10-22 20:47:36 -04:00
parent d5c844f18d
commit efdc5cdff3
2 changed files with 17 additions and 4 deletions

View file

@ -60,8 +60,13 @@ struct sample {
} data[];
};
/** Request \p cnt samples from memory pool \p p and initialize them. */
int sample_get_many(struct pool *p, struct sample *smps[], int cnt);
/** Request \p cnt samples from memory pool \p p and initialize them.
* This will leave the reference count of the sample to zero.
* Use the sample_get() function to increase it. */
int sample_alloc(struct pool *p, struct sample *smps[], int cnt);
/** Release an array of samples back to their pools */
void sample_free(struct sample *smps[], int cnt);
/** Increase reference count of sample */
int sample_get(struct sample *s);

View file

@ -12,19 +12,27 @@
#include "sample.h"
#include "timing.h"
int sample_get_many(struct pool *p, struct sample *smps[], int cnt) {
int sample_alloc(struct pool *p, struct sample *smps[], int cnt) {
int ret;
ret = pool_get_many(p, (void **) smps, cnt);
if (ret < 0)
return ret;
for (int i = 0; i < ret; i++)
for (int i = 0; i < ret; i++) {
smps[i]->capacity = (p->blocksz - sizeof(**smps)) / sizeof(smps[0]->data[0]);
smps[i]->pool = p;
}
return ret;
}
void sample_free(struct sample *smps[], int cnt)
{
for (int i = 0; i < cnt; i++)
pool_put(smps[i]->pool, smps[i]);
}
int sample_get(struct sample *s)
{
return atomic_fetch_add(&s->refcnt, 1) + 1;