[vlc-commits] picture_pool: simplify allocation
Rémi Denis-Courmont
git at videolan.org
Fri Jun 26 20:19:33 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jun 25 21:02:46 2015 +0300| [ac91416b248e44b024ed4aed712095b2a4f6ab06] | committer: Rémi Denis-Courmont
picture_pool: simplify allocation
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ac91416b248e44b024ed4aed712095b2a4f6ab06
---
src/misc/picture_pool.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 00353e1..34e3089 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -46,15 +46,14 @@ struct picture_gc_sys_t {
};
struct picture_pool_t {
- uint64_t tick;
- /* */
- unsigned picture_count;
- picture_t **picture;
-
+ uint64_t tick;
int (*pic_lock)(picture_t *);
void (*pic_unlock)(picture_t *);
- unsigned refs;
vlc_mutex_t lock;
+
+ unsigned refs;
+ unsigned picture_count;
+ picture_t *picture[];
};
void picture_pool_Release(picture_pool_t *pool)
@@ -79,7 +78,6 @@ void picture_pool_Release(picture_pool_t *pool)
}
vlc_mutex_destroy(&pool->lock);
- free(pool->picture);
free(pool);
}
@@ -134,22 +132,17 @@ static picture_t *picture_pool_ClonePicture(picture_pool_t *pool,
picture_pool_t *picture_pool_NewExtended(const picture_pool_configuration_t *cfg)
{
- picture_pool_t *pool = malloc(sizeof (*pool));
+ picture_pool_t *pool = malloc(sizeof (*pool)
+ + cfg->picture_count * sizeof (picture_t *));
if (unlikely(pool == NULL))
return NULL;
pool->tick = 1;
- pool->picture_count = cfg->picture_count;
- pool->picture = calloc(pool->picture_count, sizeof (*pool->picture));
- if (unlikely(pool->picture == NULL)) {
- free(pool);
- return NULL;
- }
-
- pool->refs = 1;
pool->pic_lock = cfg->lock;
pool->pic_unlock = cfg->unlock;
vlc_mutex_init(&pool->lock);
+ pool->refs = 1;
+ pool->picture_count = cfg->picture_count;
for (unsigned i = 0; i < cfg->picture_count; i++) {
picture_t *picture = picture_pool_ClonePicture(pool, cfg->picture[i]);
More information about the vlc-commits
mailing list