source: trunk/libs/newlib/src/newlib/libc/reent/reent.tex @ 543

Last change on this file since 543 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 4.0 KB
Line 
1@node Reentrancy
2@chapter Reentrancy
3
4@cindex reentrancy
5Reentrancy is a characteristic of library functions which allows multiple
6processes to use the same address space with assurance that the values stored
7in those spaces will remain constant between calls. The Red Hat
8newlib implementation of the library functions ensures that
9whenever possible, these library functions are reentrant.  However,
10there are some functions that can not be trivially made reentrant.
11Hooks have been provided to allow you to use these functions in a fully
12reentrant fashion.
13
14@findex _reent
15@findex reent.h
16@cindex reentrancy structure
17These hooks use the structure @code{_reent} defined in @file{reent.h}.
18A variable defined as @samp{struct _reent} is called a @dfn{reentrancy
19structure}.  All functions which must manipulate global information are
20available in two versions.  The first version has the usual name, and
21uses a single global instance of the reentrancy structure.  The second
22has a different name, normally formed by prepending @samp{_} and
23appending @samp{_r}, and takes a pointer to the particular reentrancy
24structure to use.
25
26For example, the function @code{fopen} takes two arguments, @var{file}
27and @var{mode}, and uses the global reentrancy structure.  The function
28@code{_fopen_r} takes the arguments, @var{struct_reent}, which is a
29pointer to an instance of the reentrancy structure, @var{file}
30and @var{mode}.
31
32There are two versions of @samp{struct _reent}, a normal one and one
33for small memory systems, controlled by the @code{_REENT_SMALL}
34definition from the (automatically included) @file{<sys/config.h>}.
35
36@cindex global reentrancy structure
37@findex _impure_ptr
38Each function which uses the global reentrancy structure uses the global
39variable @code{_impure_ptr}, which points to a reentrancy structure.
40
41This means that you have two ways to achieve reentrancy.  Both require
42that each thread of execution control initialize a unique global
43variable of type @samp{struct _reent}:
44
45@enumerate
46@item
47@cindex extra argument, reentrant fns
48Use the reentrant versions of the library functions, after initializing
49a global reentrancy structure for each process.  Use the pointer to this
50structure as the extra argument for all library functions.
51
52@item
53Ensure that each thread of execution control has a pointer to its own
54unique reentrancy structure in the global variable @code{_impure_ptr},
55and call the standard library subroutines.
56@end enumerate
57
58@cindex list of reentrant functions
59@cindex reentrant function list
60The following functions are provided in both reentrant
61and non-reentrant versions.
62
63@example
64@exdent @emph{Equivalent for errno variable:}
65_errno_r
66
67@exdent @emph{Locale functions:}
68_localeconv__setlocale_r
69
70@exdent @emph{Equivalents for stdio variables:}
71_stdin_r        _stdout_r       _stderr_r
72
73@page 
74@exdent @emph{Stdio functions:}
75_fdopen_r       _perror_r       _tempnam_r
76_fopen_r        _putchar_r      _tmpnam_r
77_getchar_r      _puts_r         _tmpfile_r
78_gets_r         _remove_r       _vfprintf_r
79_iprintf_r      _rename_r       _vsnprintf_r
80_mkstemp_r      _snprintf_r     _vsprintf_r
81_mktemp_t       _sprintf_r
82
83@exdent @emph{Signal functions:}
84_init_signal__signal_r
85_kill_r         __sigtramp_r
86_raise_r
87
88@exdent @emph{Stdlib functions:}
89_calloc_r       _mblen_r        _setenv_r
90_dtoa_r         _mbstowcs_r     _srand_r
91_free_r         _mbtowc_r       _strtod_r
92_getenv_r       _memalign_r     _strtol_r
93_mallinfo_r     _mstats_r       _strtoul_r
94_malloc_r       _putenv_r       _system_r
95_malloc_r       _rand_r         _wcstombs_r
96_malloc_stats_r _realloc_r      _wctomb_r
97
98@exdent @emph{String functions:}
99_strdup_r       _strtok_r
100
101@exdent @emph{System functions:}
102_close_r        _link_r         _unlink_r
103_execve_r       _lseek_r        _wait_r
104_fcntl_r        _open_r         _write_r
105_fork_r         _read_r
106_fstat_r        _sbrk_r
107_gettimeofday_r _stat_r
108_getpid_r       _times_r
109
110@ifset STDIO64
111@exdent @emph{Additional 64-bit I/O System functions:}
112_fstat64_r      _lseek64_r      _open64_r
113@end ifset
114
115@exdent @emph{Time function:}
116_asctime_r
117@end example
Note: See TracBrowser for help on using the repository browser.