termux-packages/packages/cups/cups-thread.c.patch

66 lines
1.5 KiB
Diff

--- src/cups/thread.c 2020-07-05 13:16:28.060000000 +0000
+++ src-mod/cups/thread.c 2020-07-05 13:18:17.010000000 +0000
@@ -145,6 +145,40 @@
pthread_rwlock_unlock(rwlock);
}
+/*
+ * '_cupsThreadAndroidSignalHandler()' - Wrapper around pthread_exit(0) to be called from a signal handler
+ */
+
+void
+_cupsThreadAndroidSignalHandler(int sig)
+{
+ pthread_exit(0);
+}
+
+/*
+ * '_cupsThreadAndroidWrapper()' - Function for wrapping a thread start with a signal handler for cancellation
+ */
+
+void *
+_cupsThreadAndroidWrapper(void *arg)
+{
+ _cups_wrapped_thread_func_t *wrapped = (_cups_wrapped_thread_func_t*) arg;
+
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = _cupsThreadAndroidSignalHandler;
+ sigaction(SIGUSR2, &actions, NULL);
+
+ _cups_thread_func_t func = wrapped->func;
+ void *func_arg = wrapped->arg;
+
+ free(wrapped);
+
+ return (*func)(func_arg);
+}
+
/*
* '_cupsThreadCancel()' - Cancel (kill) a thread.
@@ -153,7 +187,7 @@
void
_cupsThreadCancel(_cups_thread_t thread)/* I - Thread ID */
{
- pthread_cancel(thread);
+ pthread_kill(thread, SIGUSR2);
}
@@ -168,7 +202,11 @@
{
pthread_t thread;
- if (pthread_create(&thread, NULL, (void *(*)(void *))func, arg))
+ _cups_wrapped_thread_func_t *wrapped = malloc(sizeof(_cups_wrapped_thread_func_t));
+ wrapped->func = func;
+ wrapped->arg = arg;
+
+ if (pthread_create(&thread, NULL, _cupsThreadAndroidWrapper, wrapped))
return (0);
else
return (thread);