/
cups-thread.c.patch
65 lines (60 loc) · 1.54 KB
/
cups-thread.c.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--- 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);