diff mbox series

[FFmpeg-devel,3/5] avfilter/dnn: fix the return value of async_thread_routine

Message ID 1639012783-32766-3-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/5] avformat/rtpdec_rfc4175: cosmetic changes | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Limin Wang Dec. 9, 2021, 1:19 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/dnn/dnn_backend_common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Guo, Yejun Dec. 9, 2021, 11:55 a.m. UTC | #1
-----Original Message-----
From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of lance.lmwang@gmail.com
Sent: 2021年12月9日 9:20
To: ffmpeg-devel@ffmpeg.org
Cc: Limin Wang <lance.lmwang@gmail.com>
Subject: [FFmpeg-devel] [PATCH 3/5] avfilter/dnn: fix the return value of async_thread_routine

From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/dnn/dnn_backend_common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c
index 6a9c4cc..8c020e5 100644
--- a/libavfilter/dnn/dnn_backend_common.c
+++ b/libavfilter/dnn/dnn_backend_common.c
@@ -83,10 +83,13 @@ static void *async_thread_routine(void *args)
     void *request = async_module->args;
 
     if (async_module->start_inference(request) != DNN_SUCCESS) {
-        return DNN_ASYNC_FAIL;
+        pthread_exit((void*)DNN_ASYNC_FAIL);
+        return NULL;

Could you share the reason for this change?
From man pthread_exit:
Performing a return from the start function of any thread other than the main  thread  results  in  an  implicit  call  to
pthread_exit(), using the function's return value as the thread's exit status.

     }
     async_module->callback(request);
-    return DNN_ASYNC_SUCCESS;
+
+    pthread_exit((void*)DNN_ASYNC_SUCCESS);
+    return NULL;
 }
 
 DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module)
Limin Wang Dec. 9, 2021, 12:35 p.m. UTC | #2
On Thu, Dec 09, 2021 at 11:55:14AM +0000, Guo, Yejun wrote:
> 
> 
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of lance.lmwang@gmail.com
> Sent: 2021年12月9日 9:20
> To: ffmpeg-devel@ffmpeg.org
> Cc: Limin Wang <lance.lmwang@gmail.com>
> Subject: [FFmpeg-devel] [PATCH 3/5] avfilter/dnn: fix the return value of async_thread_routine
> 
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/dnn/dnn_backend_common.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c
> index 6a9c4cc..8c020e5 100644
> --- a/libavfilter/dnn/dnn_backend_common.c
> +++ b/libavfilter/dnn/dnn_backend_common.c
> @@ -83,10 +83,13 @@ static void *async_thread_routine(void *args)
>      void *request = async_module->args;
>  
>      if (async_module->start_inference(request) != DNN_SUCCESS) {
> -        return DNN_ASYNC_FAIL;
> +        pthread_exit((void*)DNN_ASYNC_FAIL);
> +        return NULL;
> 
> Could you share the reason for this change?
> From man pthread_exit:
> Performing a return from the start function of any thread other than the main  thread  results  in  an  implicit  call  to
> pthread_exit(), using the function's return value as the thread's exit status.
it's void * for the thread function, so I think it's right to return NULL instead of error code. Most of usage is 
pthread_exit(NULL). I want to keep the old code return, so use (void*) for that, I'm not sure it's good idea or not.

> 
>      }
>      async_module->callback(request);
> -    return DNN_ASYNC_SUCCESS;
> +
> +    pthread_exit((void*)DNN_ASYNC_SUCCESS);
> +    return NULL;
>  }
>  
>  DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module)
> -- 
> 1.8.3.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Limin Wang Dec. 9, 2021, 1:12 p.m. UTC | #3
On Thu, Dec 09, 2021 at 11:55:14AM +0000, Guo, Yejun wrote:
> 
> 
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of lance.lmwang@gmail.com
> Sent: 2021年12月9日 9:20
> To: ffmpeg-devel@ffmpeg.org
> Cc: Limin Wang <lance.lmwang@gmail.com>
> Subject: [FFmpeg-devel] [PATCH 3/5] avfilter/dnn: fix the return value of async_thread_routine
> 
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/dnn/dnn_backend_common.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c
> index 6a9c4cc..8c020e5 100644
> --- a/libavfilter/dnn/dnn_backend_common.c
> +++ b/libavfilter/dnn/dnn_backend_common.c
> @@ -83,10 +83,13 @@ static void *async_thread_routine(void *args)
>      void *request = async_module->args;
>  
>      if (async_module->start_inference(request) != DNN_SUCCESS) {
> -        return DNN_ASYNC_FAIL;
> +        pthread_exit((void*)DNN_ASYNC_FAIL);
> +        return NULL;
> 
> Could you share the reason for this change?
> From man pthread_exit:
> Performing a return from the start function of any thread other than the main  thread  results  in  an  implicit  call  to
> pthread_exit(), using the function's return value as the thread's exit status.

I just realized it should be OK to add (void*) to the error code directly.

> 
>      }
>      async_module->callback(request);
> -    return DNN_ASYNC_SUCCESS;
> +
> +    pthread_exit((void*)DNN_ASYNC_SUCCESS);
> +    return NULL;
>  }
>  
>  DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module)
> -- 
> 1.8.3.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer Dec. 9, 2021, 2 p.m. UTC | #4
On Thu, Dec 09, 2021 at 09:19:41AM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/dnn/dnn_backend_common.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c
> index 6a9c4cc..8c020e5 100644
> --- a/libavfilter/dnn/dnn_backend_common.c
> +++ b/libavfilter/dnn/dnn_backend_common.c
> @@ -83,10 +83,13 @@ static void *async_thread_routine(void *args)
>      void *request = async_module->args;
>  
>      if (async_module->start_inference(request) != DNN_SUCCESS) {
> -        return DNN_ASYNC_FAIL;
> +        pthread_exit((void*)DNN_ASYNC_FAIL);
> +        return NULL;
>      }
>      async_module->callback(request);
> -    return DNN_ASYNC_SUCCESS;
> +
> +    pthread_exit((void*)DNN_ASYNC_SUCCESS);
> +    return NULL;
>  }

seems to break build on mingw64


src/libavfilter/dnn/dnn_backend_common.c: In function ‘async_thread_routine’:
src/libavfilter/dnn/dnn_backend_common.c:86:9: error: implicit declaration of function ‘pthread_exit’; did you mean ‘pthread_join’? [-Werror=implicit-function-declaration]
         pthread_exit((void*)DNN_ASYNC_FAIL);
         ^~~~~~~~~~~~
         pthread_join
src/libavfilter/dnn/dnn_backend_common.c: In function ‘ff_dnn_async_module_cleanup’:
src/libavfilter/dnn/dnn_backend_common.c:97:11: warning: unused variable ‘status’ [-Wunused-variable]
     void *status = 0;
           ^~~~~~
src/libavfilter/dnn/dnn_backend_common.c: In function ‘ff_dnn_start_inference_async’:
src/libavfilter/dnn/dnn_backend_common.c:117:11: warning: unused variable ‘status’ [-Wunused-variable]
     void *status = 0;
           ^~~~~~
src/libavfilter/dnn/dnn_backend_common.c:116:9: warning: unused variable ‘ret’ [-Wunused-variable]
     int ret;
         ^~~
At top level:
src/libavfilter/dnn/dnn_backend_common.c:80:14: warning: ‘async_thread_routine’ defined but not used [-Wunused-function]
 static void *async_thread_routine(void *args)
              ^~~~~~~~~~~~~~~~~~~~

[...]
Limin Wang Dec. 9, 2021, 2:19 p.m. UTC | #5
On Thu, Dec 09, 2021 at 03:00:06PM +0100, Michael Niedermayer wrote:
> On Thu, Dec 09, 2021 at 09:19:41AM +0800, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavfilter/dnn/dnn_backend_common.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c
> > index 6a9c4cc..8c020e5 100644
> > --- a/libavfilter/dnn/dnn_backend_common.c
> > +++ b/libavfilter/dnn/dnn_backend_common.c
> > @@ -83,10 +83,13 @@ static void *async_thread_routine(void *args)
> >      void *request = async_module->args;
> >  
> >      if (async_module->start_inference(request) != DNN_SUCCESS) {
> > -        return DNN_ASYNC_FAIL;
> > +        pthread_exit((void*)DNN_ASYNC_FAIL);
> > +        return NULL;
> >      }
> >      async_module->callback(request);
> > -    return DNN_ASYNC_SUCCESS;
> > +
> > +    pthread_exit((void*)DNN_ASYNC_SUCCESS);
> > +    return NULL;
> >  }
> 
> seems to break build on mingw64
> 
> 

It's strange, for I saw pthread_exit() is used by vf_libvmaf.c. Anyway,
I realized it should be OK to add (void*) before the error code. 

> src/libavfilter/dnn/dnn_backend_common.c: In function ‘async_thread_routine’:
> src/libavfilter/dnn/dnn_backend_common.c:86:9: error: implicit declaration of function ‘pthread_exit’; did you mean ‘pthread_join’? [-Werror=implicit-function-declaration]
>          pthread_exit((void*)DNN_ASYNC_FAIL);
>          ^~~~~~~~~~~~
>          pthread_join
> src/libavfilter/dnn/dnn_backend_common.c: In function ‘ff_dnn_async_module_cleanup’:
> src/libavfilter/dnn/dnn_backend_common.c:97:11: warning: unused variable ‘status’ [-Wunused-variable]
>      void *status = 0;
>            ^~~~~~
> src/libavfilter/dnn/dnn_backend_common.c: In function ‘ff_dnn_start_inference_async’:
> src/libavfilter/dnn/dnn_backend_common.c:117:11: warning: unused variable ‘status’ [-Wunused-variable]
>      void *status = 0;
>            ^~~~~~
> src/libavfilter/dnn/dnn_backend_common.c:116:9: warning: unused variable ‘ret’ [-Wunused-variable]
>      int ret;
>          ^~~
> At top level:
> src/libavfilter/dnn/dnn_backend_common.c:80:14: warning: ‘async_thread_routine’ defined but not used [-Wunused-function]
>  static void *async_thread_routine(void *args)
>               ^~~~~~~~~~~~~~~~~~~~
> 
> [...]
> -- 
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> The greatest way to live with honor in this world is to be what we pretend
> to be. -- Socrates



> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c
index 6a9c4cc..8c020e5 100644
--- a/libavfilter/dnn/dnn_backend_common.c
+++ b/libavfilter/dnn/dnn_backend_common.c
@@ -83,10 +83,13 @@  static void *async_thread_routine(void *args)
     void *request = async_module->args;
 
     if (async_module->start_inference(request) != DNN_SUCCESS) {
-        return DNN_ASYNC_FAIL;
+        pthread_exit((void*)DNN_ASYNC_FAIL);
+        return NULL;
     }
     async_module->callback(request);
-    return DNN_ASYNC_SUCCESS;
+
+    pthread_exit((void*)DNN_ASYNC_SUCCESS);
+    return NULL;
 }
 
 DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module)