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

some fixes for memory pool

This commit is contained in:
Steffen Vogel 2016-10-19 01:35:41 -04:00
parent 291033fd25
commit e95c50a827
2 changed files with 10 additions and 7 deletions

View file

@ -15,8 +15,7 @@
#include <sys/types.h>
#include "queue.h"
struct memtype;
#include "memory.h"
/** A thread-safe memory pool */
struct pool {
@ -34,7 +33,7 @@ struct pool {
#define INLINE static inline __attribute__((unused))
/** Initiazlize a pool */
int pool_init(struct pool *p, size_t blocksz, size_t alignment, const struct memtype *mem);
int pool_init(struct pool *p, size_t cnt, size_t blocksz, const struct memtype *mem);
/** Destroy and release memory used by pool. */
int pool_destroy(struct pool *p);

View file

@ -12,8 +12,10 @@
#include "memory.h"
#include "kernel/kernel.h"
int pool_init(struct pool *p, size_t blocksz, size_t cnt, const struct memtype *m)
int pool_init(struct pool *p, size_t cnt, size_t blocksz, const struct memtype *m)
{
int ret;
/* Make sure that we use a block size that is aligned to the size of a cache line */
p->alignment = kernel_get_cacheline_size();
p->blocksz = blocksz * CEIL(blocksz, p->alignment);
@ -25,12 +27,14 @@ int pool_init(struct pool *p, size_t blocksz, size_t cnt, const struct memtype *
serror("Failed to allocate memory for memory pool");
else
debug(DBG_POOL | 4, "Allocated %#zx bytes for memory pool", p->len);
queue_init(&p->queue, cnt, m);
ret = queue_init(&p->queue, cnt, m);
if (ret)
return ret;
for (int i = 0; i < cnt; i++)
queue_push(&p->queue, (char *) p->buffer + i * p->blocksz);
return 0;
}