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

add sample_pool() macro to hide relative pointers

This commit is contained in:
Steffen Vogel 2017-08-30 23:50:57 +02:00
parent 313193140d
commit c2000e78b1
3 changed files with 7 additions and 9 deletions

View file

@ -83,6 +83,8 @@ struct sample {
} data[]; /**< Data is in host endianess! */
};
#define sample_pool(s) ((struct pool *) ((char *) (s) + (s)->pool_off))
/** Request \p cnt samples from memory pool \p p and initialize them.
* The reference count will already be set to 1.
* Use the sample_get() function to increase it. */

View file

@ -81,7 +81,7 @@ static int map_read(struct hook *h, struct sample *smps[], unsigned *cnt)
if (*cnt <= 0)
return 0;
ret = sample_alloc((struct pool *) ((char* ) smps[0] + smps[0]->pool_off), tmp, *cnt);
ret = sample_alloc(sample_pool(smps[0]), tmp, *cnt);
if (ret != *cnt)
return ret;

View file

@ -46,10 +46,8 @@ int sample_alloc(struct pool *p, struct sample *smps[], int cnt)
void sample_free(struct sample *smps[], int cnt)
{
for (int i = 0; i < cnt; i++) {
struct pool *p = (struct pool *) ((char *) smps[i] + smps[i]->pool_off);
pool_put(p, smps[i]);
}
for (int i = 0; i < cnt; i++)
pool_put(sample_pool(smps[i]), smps[i]);
}
int sample_put_many(struct sample *smps[], int cnt)
@ -82,10 +80,8 @@ int sample_put(struct sample *s)
int prev = atomic_fetch_sub(&s->refcnt, 1);
/* Did we had the last reference? */
if (prev == 1) {
struct pool *p = (struct pool *) ((char *) s + s->pool_off);
pool_put(p, s);
}
if (prev == 1)
pool_put(sample_pool(s), s);
return prev - 1;
}