diff options
author | Florian Weimer <fweimer@redhat.com> | 2019-05-02 11:42:51 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2019-05-02 11:42:51 +0200 |
commit | 7b807a35a8dc63f9742cecf0fc3db46c30e28b0d (patch) | |
tree | 0dce83854245814394b46373b4c8316ab7610b0c /manual/search.texi | |
parent | 20aa5819586ac7ad11f711bab64feda307965191 (diff) | |
download | glibc-7b807a35a8dc63f9742cecf0fc3db46c30e28b0d.tar.gz glibc-7b807a35a8dc63f9742cecf0fc3db46c30e28b0d.tar.xz glibc-7b807a35a8dc63f9742cecf0fc3db46c30e28b0d.zip |
misc: Add twalk_r function
The twalk function is very difficult to use in a multi-threaded program because there is no way to pass external state to the iterator function. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'manual/search.texi')
-rw-r--r-- | manual/search.texi | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/manual/search.texi b/manual/search.texi index 1574c96562..979732f027 100644 --- a/manual/search.texi +++ b/manual/search.texi @@ -618,5 +618,28 @@ Since the functions used for the @var{action} parameter to @code{twalk} must not modify the tree data, it is safe to run @code{twalk} in more than one thread at the same time, working on the same tree. It is also safe to call @code{tfind} in parallel. Functions which modify the tree -must not be used, otherwise the behavior is undefined. +must not be used, otherwise the behavior is undefined. However, it is +difficult to pass data external to the tree to the callback function +without resorting to global variables (and thread safety issues), so +see the @code{twalk_r} function below. +@end deftypefun + +@deftypefun void twalk_r (const void *@var{root}, void (*@var{action}) (const void *@var{key}, VISIT @var{which}, void *@var{closure}), void *@var{closure}) +@standards{GNU, search.h} +@safety{@prelim{}@mtsafe{@mtsrace{:root}}@assafe{}@acsafe{}} +For each node in the tree with a node pointed to by @var{root}, the +@code{twalk_r} function calls the function provided by the parameter +@var{action}. For leaf nodes the function is called exactly once with +@var{value} set to @code{leaf}. For internal nodes the function is +called three times, setting the @var{value} parameter or @var{action} to +the appropriate value. The @var{closure} parameter is passed down to +each call of the @var{action} function, unmodified. + +It is possible to implement the @code{twalk} function on top of the +@code{twalk_r} function, which is why there is no separate level +parameter. + +@smallexample +@include twalk.c.texi +@end smallexample @end deftypefun |