Copyright 2020 Thomas E. Dickey *
Copyright 2008-2015,2017 Free Software Foundation, Inc. *
*
Permission is hereby granted, free of charge, to any person obtaining a *
copy of this software and associated documentation files (the *
"Software"), to deal in the Software without restriction, including *
without limitation the rights to use, copy, modify, merge, publish, *
distribute, distribute with modifications, sublicense, and/or sell *
copies of the Software, and to permit persons to whom the Software is *
furnished to do so, subject to the following conditions: *
*
The above copyright notice and this permission notice shall be included *
in all copies or substantial portions of the Software. *
*
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
*
Except as contained in this notice, the name(s) of the above copyright *
holders shall not be used in advertising or otherwise to promote the *
sale, use or other dealings in this Software without prior written *
authorization. *
***************************************************************************
$Id: curs_threads.3x,v 1.27 2020/12/30 18:28:51 tom Exp $
typedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *); int get_escdelay(void);
int set_escdelay(int ms);
int set_tabsize(int cols); int use_screen(SCREEN *scr, NCURSES_SCREEN_CB func, void *data);
int use_window(WINDOW *win, NCURSES_WINDOW_CB func, void *data);
Rather than modify the interfaces to pass a thread specifier to each function, it adds a few functions which can be used in any configuration which hide the mutex's needed to prevent concurrent use of the global variables when configured for threading.
In addition to forcing access to members of the WINDOW structure to be via functions (see curs_opaque(3X)), it makes functions of the common global variables, e.g., COLORS, COLOR_PAIRS, COLS, ESCDELAY, LINES, TABSIZE curscr, newscr and ttytype. Those variables are maintained as read-only values, stored in the SCREEN structure.
Even this is not enough to make a thread-safe application using curses. A multi-threaded application would be expected to have threads updating separate windows (within the same device), or updating on separate screens (on different devices). Also, a few of the global variables are considered writable by some applications. The functions described here address these special situations.
The ESCDELAY and TABSIZE global variables are modified by some applications. To modify them in any configuration, use the set_escdelay or set_tabsize functions. Other global variables are not modifiable.
The get_escdelay function returns the value for ESCDELAY.
The use_window and use_screen functions provide coarse
granularity mutexes for their respective WINDOW and SCREEN
parameters, and call a user-supplied function,
passing it a data parameter,
and returning the value from the user-supplied function to the application.
***************************************************************************
.bP global data, e.g., used in the low-level terminfo or termcap interfaces. .bP terminal data, e.g., associated with a call to set_curterm. The terminal data are initialized when screens are created. .bP screen data, e.g., associated with a call to newterm or initscr. .bP window data, e.g., associated with a call to newwin or subwin. Windows are associated with screens. Pads are not necessarily associated with a particular screen.
Most curses applications operate on one or more windows within a single screen. .bP reentrant, i.e., it uses only the data passed as parameters.This table lists the scope of data used for each symbol in the ncurses library when it is configured to support threading:
***************************************************************************