a05b788a78
Add pthread_cancel replacement through atomic_flag instead of using pthread_kill(thread, 0). Fixes https://github.com/termux/termux-packages/issues/4378.
140 lines
4.1 KiB
Diff
140 lines
4.1 KiB
Diff
diff -uNr calcurse-4.6.0/src/io.c calcurse-4.6.0.mod/src/io.c
|
|
--- calcurse-4.6.0/src/io.c 2020-03-27 15:14:07.000000000 +0200
|
|
+++ calcurse-4.6.0.mod/src/io.c 2020-10-01 20:39:41.632326755 +0300
|
|
@@ -44,6 +44,7 @@
|
|
#include <math.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
+#include <stdatomic.h>
|
|
|
|
#include "calcurse.h"
|
|
#include "sha1.h"
|
|
@@ -69,6 +70,8 @@
|
|
static char apts_sha1[SHA1_DIGESTLEN * 2 + 1];
|
|
static char todo_sha1[SHA1_DIGESTLEN * 2 + 1];
|
|
|
|
+static atomic_flag psave_thread_cancel;
|
|
+
|
|
/* Ask user for a file name to export data to. */
|
|
static FILE *get_export_stream(enum export_type type)
|
|
{
|
|
@@ -1455,12 +1458,15 @@
|
|
/* Thread used to periodically save data. */
|
|
static void *io_psave_thread(void *arg)
|
|
{
|
|
+ atomic_flag_clear(&psave_thread_cancel);
|
|
+
|
|
int delay = conf.periodic_save;
|
|
EXIT_IF(delay < 0, _("Invalid delay"));
|
|
char *mesg = _("Periodic save: data files have changed. Save cancelled.");
|
|
|
|
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
|
for (;;) {
|
|
+ if (atomic_flag_test_and_set(&psave_thread_cancel)) pthread_exit(NULL);
|
|
+ atomic_flag_clear(&psave_thread_cancel);
|
|
sleep(delay * MININSEC);
|
|
pthread_mutex_lock(&io_periodic_save_mutex);
|
|
if (io_save_cal(periodic) == IO_SAVE_CANCEL)
|
|
@@ -1484,8 +1490,7 @@
|
|
|
|
/* Lock the mutex to avoid cancelling the thread during saving. */
|
|
pthread_mutex_lock(&io_periodic_save_mutex);
|
|
- pthread_cancel(io_t_psave);
|
|
- pthread_join(io_t_psave, NULL);
|
|
+ atomic_flag_test_and_set(&psave_thread_cancel);
|
|
pthread_mutex_unlock(&io_periodic_save_mutex);
|
|
io_t_psave = pthread_self();
|
|
}
|
|
diff -uNr calcurse-4.6.0/src/notify.c calcurse-4.6.0.mod/src/notify.c
|
|
--- calcurse-4.6.0/src/notify.c 2020-02-04 23:46:34.000000000 +0200
|
|
+++ calcurse-4.6.0.mod/src/notify.c 2020-10-01 20:39:57.884475331 +0300
|
|
@@ -38,6 +38,7 @@
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
+#include <stdatomic.h>
|
|
|
|
#include "calcurse.h"
|
|
|
|
@@ -55,6 +56,8 @@
|
|
static struct notify_app notify_app;
|
|
static pthread_attr_t detached_thread_attr;
|
|
|
|
+static atomic_flag main_thread_cancel;
|
|
+
|
|
/*
|
|
* Return the number of seconds before next appointment
|
|
* (0 if no upcoming appointment).
|
|
@@ -196,8 +199,7 @@
|
|
if (pthread_equal(notify_t_main, pthread_self()))
|
|
return;
|
|
|
|
- pthread_cancel(notify_t_main);
|
|
- pthread_join(notify_t_main, NULL);
|
|
+ atomic_flag_test_and_set(&main_thread_cancel);
|
|
notify_t_main = pthread_self();
|
|
}
|
|
|
|
@@ -334,6 +336,8 @@
|
|
/* ARGSUSED0 */
|
|
static void *notify_main_thread(void *arg)
|
|
{
|
|
+ atomic_flag_clear(&main_thread_cancel);
|
|
+
|
|
const unsigned thread_sleep = 1;
|
|
const unsigned check_app = MININSEC;
|
|
int elapse = 0;
|
|
@@ -346,6 +350,8 @@
|
|
pthread_cleanup_push(notify_main_thread_cleanup, NULL);
|
|
|
|
for (;;) {
|
|
+ if (atomic_flag_test_and_set(&main_thread_cancel)) pthread_exit(NULL);
|
|
+ atomic_flag_clear(&main_thread_cancel);
|
|
ntimer = time(NULL);
|
|
localtime_r(&ntimer, &ntime);
|
|
pthread_mutex_lock(¬ify.mutex);
|
|
diff -uNr calcurse-4.6.0/src/ui-calendar.c calcurse-4.6.0.mod/src/ui-calendar.c
|
|
--- calcurse-4.6.0/src/ui-calendar.c 2020-02-04 23:46:34.000000000 +0200
|
|
+++ calcurse-4.6.0.mod/src/ui-calendar.c 2020-10-01 20:40:09.024576943 +0300
|
|
@@ -41,6 +41,7 @@
|
|
#include <time.h>
|
|
#include <math.h>
|
|
#include <langinfo.h>
|
|
+#include <stdatomic.h>
|
|
|
|
#include "calcurse.h"
|
|
|
|
@@ -59,6 +60,8 @@
|
|
static int monthly_view_cache_valid = 0;
|
|
static int monthly_view_cache_month = 0;
|
|
|
|
+static atomic_flag date_thread_cancel;
|
|
+
|
|
/* Switch between calendar views (monthly view is selected by default). */
|
|
void ui_calendar_view_next(void)
|
|
{
|
|
@@ -89,9 +92,13 @@
|
|
/* ARGSUSED0 */
|
|
static void *ui_calendar_date_thread(void *arg)
|
|
{
|
|
+ atomic_flag_clear(&date_thread_cancel);
|
|
+
|
|
time_t actual, tomorrow;
|
|
|
|
for (;;) {
|
|
+ if (atomic_flag_test_and_set(&date_thread_cancel)) pthread_exit(NULL);
|
|
+ atomic_flag_clear(&date_thread_cancel);
|
|
tomorrow = date2sec(today, 24, 0);
|
|
|
|
while ((actual = time(NULL)) < tomorrow)
|
|
@@ -118,8 +125,7 @@
|
|
if (pthread_equal(ui_calendar_t_date, pthread_self()))
|
|
return;
|
|
|
|
- pthread_cancel(ui_calendar_t_date);
|
|
- pthread_join(ui_calendar_t_date, NULL);
|
|
+ atomic_flag_test_and_set(&date_thread_cancel);
|
|
ui_calendar_t_date = pthread_self();
|
|
}
|
|
|