gnuchess: Use alternative `pthread_cancel` workaround

This commit is contained in:
Tee KOBAYASHI 2022-12-13 09:30:52 +09:00 committed by xtkoba
parent 5abf5e869a
commit ba3ac030ce
4 changed files with 71 additions and 13 deletions

View File

@ -3,9 +3,9 @@ TERMUX_PKG_DESCRIPTION="Chess-playing program"
TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=6.2.9
TERMUX_PKG_REVISION=1
TERMUX_PKG_REVISION=2
TERMUX_PKG_SRCURL=https://mirrors.kernel.org/gnu/chess/gnuchess-${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=ddfcc20bdd756900a9ab6c42c7daf90a2893bf7f19ce347420ce36baebc41890
TERMUX_PKG_DEPENDS="libc++, ncurses, readline"
TERMUX_PKG_DEPENDS="readline"
TERMUX_PKG_RM_AFTER_INSTALL="bin/gnuchessu bin/gnuchessx"
TERMUX_PKG_GROUPS="games"

View File

@ -1,11 +0,0 @@
diff -uNr gnuchess-6.2.5/src/components.cc gnuchess-6.2.5.mod/src/components.cc
--- gnuchess-6.2.5/src/components.cc 2017-06-11 18:17:14.000000000 +0300
+++ gnuchess-6.2.5.mod/src/components.cc 2018-11-09 14:17:10.952608702 +0200
@@ -171,6 +171,6 @@
void TerminateInput()
{
- pthread_cancel( input_thread );
+ pthread_kill( input_thread, 0 );
pthread_join( input_thread, NULL );
}

View File

@ -0,0 +1,69 @@
--- a/src/components.cc
+++ b/src/components.cc
@@ -74,6 +74,37 @@ int pipefd_e2a[2];
return 0;
}*/
+#ifdef __ANDROID__
+typedef struct wrapped_thread_start {
+ void *(*start)(void *);
+ void *arg;
+} wrapped_thread_start_t;
+
+static void thread_signal_handler(int signum)
+{
+ pthread_exit(0);
+}
+
+static void *pthread_create_wrapper(void *wrapped_arg)
+{
+ wrapped_thread_start_t *wrapped_start = (wrapped_thread_start_t *)wrapped_arg;
+
+ struct sigaction actions;
+ memset( &actions, 0, sizeof( actions ) );
+ sigemptyset( &actions.sa_mask );
+ actions.sa_flags = 0;
+ actions.sa_handler = thread_signal_handler;
+ sigaction( SIGUSR2, &actions, NULL );
+
+ void *(*start)(void *) = wrapped_start->start;
+ void *arg = wrapped_start->arg;
+
+ free( wrapped_start );
+
+ return (*start)( arg );
+}
+#endif
+
/*
* Starts the input on a separate thread.
*/
@@ -87,7 +118,17 @@ void InitInputThread()
}
/* Start input thread */
+#ifndef __ANDROID__
pthread_create(&input_thread, NULL, input_func, NULL);
+#else
+ wrapped_thread_start_t *wrapped_start = (wrapped_thread_start_t *)malloc( sizeof( wrapped_thread_start_t ) );
+ if ( wrapped_start == NULL ) {
+ return;
+ }
+ wrapped_start->start = input_func;
+ wrapped_start->arg = NULL;
+ pthread_create( &input_thread, NULL, pthread_create_wrapper, wrapped_start );
+#endif
}
/*
@@ -171,6 +212,10 @@ void TerminateAdapterEngine()
void TerminateInput()
{
+#ifndef __ANDROID__
pthread_cancel( input_thread );
+#else
+ pthread_kill( input_thread, SIGUSR2 );
+#endif
pthread_join( input_thread, NULL );
}