[PATCH 3/5] Avoid use of pthread_cancel by introducing an exit flag
Dixit, Ashutosh
ashutosh.dixit at intel.com
Tue Apr 29 20:29:19 UTC 2025
On Tue, 29 Apr 2025 12:57:43 -0700, Jeevaka Prabu Badrappan wrote:
>
> Android build fails due to pthread_cancel unavailability.
> Replace pthread_cancel with thread exit based on an exit flag.
How about adding the definition of pthread_cancel() in an android specific
library and using that, rather than making changes here?
I would think that approach might be better in general, calling into the
android specific library, rather than using '#ifdef ANDROID' as seems to be
done in other patches here?
Thoughts?
>
> Signed-off-by: Jeevaka Prabu Badrappan <jeevaka.badrappan at intel.com>
> ---
> lib/igt_dummyload.c | 6 +++---
> lib/igt_dummyload.h | 2 ++
> lib/xe/xe_spin.c | 2 +-
> 3 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
> index 3cf80b762..38249afb7 100644
> --- a/lib/igt_dummyload.c
> +++ b/lib/igt_dummyload.c
> @@ -530,7 +530,7 @@ static void *timer_thread(void *data)
> /* Wait until we see the timer fire, or we get cancelled */
> do {
> read(spin->timerfd, &overruns, sizeof(overruns));
> - } while (!overruns);
> + } while (!overruns && !spin->exit_thread);
>
> igt_spin_end(spin);
> return NULL;
> @@ -565,7 +565,7 @@ void igt_spin_set_timeout(igt_spin_t *spin, int64_t ns)
> timerfd = timerfd_create(CLOCK_MONOTONIC, 0);
> igt_assert(timerfd >= 0);
> spin->timerfd = timerfd;
> -
> + spin->exit_thread = false;
> pthread_attr_init(&attr);
> pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
> pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
> @@ -631,7 +631,7 @@ void igt_spin_end(igt_spin_t *spin)
> static void __igt_spin_free(int fd, igt_spin_t *spin)
> {
> if (spin->timerfd >= 0) {
> - pthread_cancel(spin->timer_thread);
> + spin->exit_thread = true;
> igt_assert(pthread_join(spin->timer_thread, NULL) == 0);
> close(spin->timerfd);
> }
> diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h
> index b771011af..07b21227d 100644
> --- a/lib/igt_dummyload.h
> +++ b/lib/igt_dummyload.h
> @@ -26,6 +26,7 @@
> #define __IGT_DUMMYLOAD_H__
>
> #include <stdint.h>
> +#include <stdatomic.h>
> #include <time.h>
>
> #include "drmtest.h"
> @@ -75,6 +76,7 @@ typedef struct igt_spin {
>
> struct timespec last_signal;
> pthread_t timer_thread;
> + atomic_bool exit_thread;
> int timerfd;
>
> int out_fence;
> diff --git a/lib/xe/xe_spin.c b/lib/xe/xe_spin.c
> index a92903b6b..2fb688179 100644
> --- a/lib/xe/xe_spin.c
> +++ b/lib/xe/xe_spin.c
> @@ -264,7 +264,7 @@ void xe_spin_free(int fd, struct igt_spin *spin)
> igt_assert(spin->driver == INTEL_DRIVER_XE);
>
> if (spin->timerfd >= 0) {
> - pthread_cancel(spin->timer_thread);
> + spin->exit_thread = true;
> igt_assert(pthread_join(spin->timer_thread, NULL) == 0);
> close(spin->timerfd);
> }
> --
> 2.49.0
>
More information about the igt-dev
mailing list