summaryrefslogtreecommitdiff
path: root/libavcodec/pthread.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-09-02 13:00:42 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-09-04 08:03:19 +0200
commita4f7fabc2684890ea9fbcfaefb7503ab6633479f (patch)
treeb07736e20e462152da7aaee8cb114f230d853c05 /libavcodec/pthread.c
parentbd95f2f599a6605dafa73b95ca7590aa6a5e941d (diff)
avcodec/pthread_frame: Move (init|free)_pthread() to pthread.c
We have more mutexes/condition variables whose initialization is unchecked. Also use a proper namespace for these functions. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/pthread.c')
-rw-r--r--libavcodec/pthread.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 14b7cca4fe..e7bad19f8b 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -29,6 +29,8 @@
* @see doc/multithreading.txt
*/
+#include "libavutil/thread.h"
+
#include "avcodec.h"
#include "internal.h"
#include "pthread_internal.h"
@@ -86,3 +88,39 @@ void ff_thread_free(AVCodecContext *avctx)
else
ff_slice_thread_free(avctx);
}
+
+av_cold void ff_pthread_free(void *obj, const unsigned offsets[])
+{
+ unsigned cnt = *(unsigned*)((char*)obj + offsets[0]);
+ const unsigned *cur_offset = offsets;
+
+ *(unsigned*)((char*)obj + offsets[0]) = 0;
+
+ for (; *(++cur_offset) != THREAD_SENTINEL && cnt; cnt--)
+ pthread_mutex_destroy((pthread_mutex_t*)((char*)obj + *cur_offset));
+ for (; *(++cur_offset) != THREAD_SENTINEL && cnt; cnt--)
+ pthread_cond_destroy ((pthread_cond_t *)((char*)obj + *cur_offset));
+}
+
+av_cold int ff_pthread_init(void *obj, const unsigned offsets[])
+{
+ const unsigned *cur_offset = offsets;
+ unsigned cnt = 0;
+ int err;
+
+#define PTHREAD_INIT_LOOP(type) \
+ for (; *(++cur_offset) != THREAD_SENTINEL; cnt++) { \
+ pthread_ ## type ## _t *dst = (void*)((char*)obj + *cur_offset); \
+ err = pthread_ ## type ## _init(dst, NULL); \
+ if (err) { \
+ err = AVERROR(err); \
+ goto fail; \
+ } \
+ }
+ PTHREAD_INIT_LOOP(mutex)
+ PTHREAD_INIT_LOOP(cond)
+
+fail:
+ *(unsigned*)((char*)obj + offsets[0]) = cnt;
+ return err;
+}