/****************************************************************************
- * Copyright 2018-2021,2022 Thomas E. Dickey *
+ * Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
/*
* Author: Thomas E. Dickey (1998-on)
*
- * $Id: ditto.c,v 1.56 2022/12/10 22:10:49 tom Exp $
+ * $Id: ditto.c,v 1.59 2023/09/23 17:08:43 tom Exp $
*
* The program illustrates how to set up multiple screens from a single
* program.
#endif
} DITTO;
+#ifdef USE_PTHREADS
+#define LockIt() pthread_mutex_lock(&pending_mutex)
+#define UnlockIt() pthread_mutex_unlock(&pending_mutex)
+pthread_mutex_t pending_mutex;
+#else
+#define LockIt() /* nothing */
+#define UnlockIt() /* nothing */
+#endif
+
/*
* Structure used to pass multiple parameters via the use_screen()
* single-parameter interface.
return TRUE;
}
+static void
+free_screen(DITTO * target)
+{
+ free(target->parents);
+ free(target->windows);
+ free(target->peeks);
+}
+
static void
open_screen(DITTO * target, char **source, int length, int which1)
{
/* NOTREACHED */
}
}
- if (optind < argc)
- usage(FALSE);
if ((data = typeCalloc(DITTO, (size_t) argc)) == 0)
failed("calloc data");
}
#ifdef USE_PTHREADS
+ pthread_mutex_init(&pending_mutex, NULL);
/*
* For multi-threaded operation, set up a reader for each of the screens.
* That uses blocking I/O rather than polling for input, so no calls to
* Cleanup and exit
*/
for (j = argc - 1; j >= 0; j--) {
+ LockIt();
USING_SCREEN(data[j].screen, close_screen, 0);
fprintf(data[j].output, "**Closed\r\n");
fflush(data[j].output);
fclose(data[j].output);
delscreen(data[j].screen);
+ free_screen(&data[j]);
+ UnlockIt();
}
+ free(data);
ExitProgram(EXIT_SUCCESS);
}
#else