summaryrefslogtreecommitdiff
path: root/libavcodec/pthread_slice.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2015-11-27 23:32:04 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2015-11-27 23:37:42 +0100
commit36205501ba2f003c6b319a6d20e39fe991ee7511 (patch)
treea6c539f28aa75519a10f7f3f79d72fe558d07c1d /libavcodec/pthread_slice.c
parentd5028f61e44b7607b6a547f218f7d85217490a5b (diff)
avcodec/pthread_slice: Allow calling ff_alloc_entries() multiple times to readjust the entry count
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/pthread_slice.c')
-rw-r--r--libavcodec/pthread_slice.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c
index e887428aa0..b2a15c6004 100644
--- a/libavcodec/pthread_slice.c
+++ b/libavcodec/pthread_slice.c
@@ -37,6 +37,7 @@
#include "pthread_internal.h"
#include "thread.h"
+#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/cpu.h"
#include "libavutil/mem.h"
@@ -276,11 +277,19 @@ int ff_alloc_entries(AVCodecContext *avctx, int count)
if (avctx->active_thread_type & FF_THREAD_SLICE) {
SliceThreadContext *p = avctx->internal->thread_ctx;
+
+ if (p->entries) {
+ av_assert0(p->thread_count == avctx->thread_count);
+ av_freep(&p->entries);
+ }
+
p->thread_count = avctx->thread_count;
p->entries = av_mallocz_array(count, sizeof(int));
- p->progress_mutex = av_malloc_array(p->thread_count, sizeof(pthread_mutex_t));
- p->progress_cond = av_malloc_array(p->thread_count, sizeof(pthread_cond_t));
+ if (!p->progress_mutex) {
+ p->progress_mutex = av_malloc_array(p->thread_count, sizeof(pthread_mutex_t));
+ p->progress_cond = av_malloc_array(p->thread_count, sizeof(pthread_cond_t));
+ }
if (!p->entries || !p->progress_mutex || !p->progress_cond) {
av_freep(&p->entries);