aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuo, Yejun <yejun.guo@intel.com>2020-12-30 10:47:29 +0800
committerGuo, Yejun <yejun.guo@intel.com>2020-12-31 08:31:17 +0800
commit97f520b700b9c250883bf6e3a06fbb6ebffc3c91 (patch)
tree10587ad2f01bcaba19f60f6828682dc6d0aeda02
parent8e78d5d394a3cdeb1da195aa901ff2f7b5b1b3ea (diff)
downloadffmpeg-97f520b700b9c250883bf6e3a06fbb6ebffc3c91.tar.gz
dnn: fix issue when pthread is not supported
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
-rw-r--r--libavfilter/dnn/safe_queue.c50
-rw-r--r--libavfilter/vf_dnn_processing.c7
2 files changed, 41 insertions, 16 deletions
diff --git a/libavfilter/dnn/safe_queue.c b/libavfilter/dnn/safe_queue.c
index 52a60982b5..559b939ec9 100644
--- a/libavfilter/dnn/safe_queue.c
+++ b/libavfilter/dnn/safe_queue.c
@@ -25,10 +25,28 @@
#include "libavutil/avassert.h"
#include "libavutil/thread.h"
+#if HAVE_PTHREAD_CANCEL
+#define DNNCond pthread_cond_t
+#define dnn_cond_init pthread_cond_init
+#define dnn_cond_destroy pthread_cond_destroy
+#define dnn_cond_signal pthread_cond_signal
+#define dnn_cond_wait pthread_cond_wait
+#else
+#define DNNCond char
+static inline int dnn_cond_init(DNNCond *cond, const void *attr) { return 0; }
+static inline int dnn_cond_destroy(DNNCond *cond) { return 0; }
+static inline int dnn_cond_signal(DNNCond *cond) { return 0; }
+static inline int dnn_cond_wait(DNNCond *cond, AVMutex *mutex)
+{
+ av_assert0(!"should not reach here");
+ return 0;
+}
+#endif
+
struct FFSafeQueue {
FFQueue *q;
- pthread_mutex_t mutex;
- pthread_cond_t cond;
+ AVMutex mutex;
+ DNNCond cond;
};
FFSafeQueue *ff_safe_queue_create(void)
@@ -41,8 +59,8 @@ FFSafeQueue *ff_safe_queue_create(void)
if (!sq->q)
return NULL;
- pthread_mutex_init(&sq->mutex, NULL);
- pthread_cond_init(&sq->cond, NULL);
+ ff_mutex_init(&sq->mutex, NULL);
+ dnn_cond_init(&sq->cond, NULL);
return sq;
}
@@ -52,8 +70,8 @@ void ff_safe_queue_destroy(FFSafeQueue *sq)
return;
ff_queue_destroy(sq->q);
- pthread_mutex_destroy(&sq->mutex);
- pthread_cond_destroy(&sq->cond);
+ ff_mutex_destroy(&sq->mutex);
+ dnn_cond_destroy(&sq->cond);
av_freep(&sq);
}
@@ -64,29 +82,29 @@ size_t ff_safe_queue_size(FFSafeQueue *sq)
void ff_safe_queue_push_front(FFSafeQueue *sq, void *v)
{
- pthread_mutex_lock(&sq->mutex);
+ ff_mutex_lock(&sq->mutex);
ff_queue_push_front(sq->q, v);
- pthread_cond_signal(&sq->cond);
- pthread_mutex_unlock(&sq->mutex);
+ dnn_cond_signal(&sq->cond);
+ ff_mutex_unlock(&sq->mutex);
}
void ff_safe_queue_push_back(FFSafeQueue *sq, void *v)
{
- pthread_mutex_lock(&sq->mutex);
+ ff_mutex_lock(&sq->mutex);
ff_queue_push_back(sq->q, v);
- pthread_cond_signal(&sq->cond);
- pthread_mutex_unlock(&sq->mutex);
+ dnn_cond_signal(&sq->cond);
+ ff_mutex_unlock(&sq->mutex);
}
void *ff_safe_queue_pop_front(FFSafeQueue *sq)
{
void *value;
- pthread_mutex_lock(&sq->mutex);
+ ff_mutex_lock(&sq->mutex);
while (ff_queue_size(sq->q) == 0) {
- pthread_cond_wait(&sq->cond, &sq->mutex);
+ dnn_cond_wait(&sq->cond, &sq->mutex);
}
value = ff_queue_pop_front(sq->q);
- pthread_cond_signal(&sq->cond);
- pthread_mutex_unlock(&sq->mutex);
+ dnn_cond_signal(&sq->cond);
+ ff_mutex_unlock(&sq->mutex);
return value;
}
diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index da4508b50e..fff5696a31 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -110,6 +110,13 @@ static av_cold int init(AVFilterContext *context)
av_log(ctx, AV_LOG_WARNING, "this backend does not support async execution, roll back to sync.\n");
}
+#if !HAVE_PTHREAD_CANCEL
+ if (ctx->async) {
+ ctx->async = 0;
+ av_log(ctx, AV_LOG_WARNING, "pthread is not supported, roll back to sync.\n");
+ }
+#endif
+
return 0;
}