Files
termux-packages/packages/gnuchess/src-components.cc.patch
2025-09-01 12:05:41 +00:00

91 lines
2.1 KiB
Diff

--- ./src/components.cc.orig 2025-05-17 10:43:35.000000000 +0000
+++ ./src/components.cc 2025-09-01 07:23:26.417318926 +0000
@@ -75,6 +75,37 @@
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.
*/
@@ -88,7 +119,17 @@
}
/* 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
}
/*
@@ -161,10 +202,18 @@
void TerminateAdapterEngine()
{
- pthread_cancel( engine_thread );
+#ifndef __ANDROID__
+ pthread_cancel( engine_thread );
+#else
+ pthread_kill( engine_thread, SIGUSR2 );
+#endif
pthread_join( engine_thread, NULL );
if ( ! (flags & UCI ) ) {
+#ifndef __ANDROID__
pthread_cancel( adapter_thread );
+#else
+ pthread_kill( adapter_thread, SIGUSR2 );
+#endif
pthread_join( adapter_thread, NULL );
}
}
@@ -172,7 +221,11 @@
void TerminateInput()
{
if ( ! (flags & UCI ) ) {
+#ifndef __ANDROID__
pthread_cancel( input_thread );
+#else
+ pthread_kill( input_thread, SIGUSR2 );
+#endif
pthread_join( input_thread, NULL );
}
}