[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
clean-temp: make multithread-safe
From: |
Bruno Haible |
Subject: |
clean-temp: make multithread-safe |
Date: |
Sat, 04 Jul 2020 14:44:43 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; ) |
With these two patches, the clean-temp module becomes multithread-safe.
The difficult part here is to avoid that two 'close (fd)' calls, one in
normal thread code and one in a signal handler, have the effect that an
unrelated file descriptor, just open()ed in another thread, could be closed.
This issue is solved through the 'asyncsafe-spin' module, as explained in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-07/msg00005.html>.
2020-07-04 Bruno Haible <bruno@clisp.org>
clean-temp: Make multithread-safe, part 2.
* lib/fatal-signal.h: Include <signal.h>.
(get_fatal_signal_set): New declaration.
* lib/fatal-signal.c (get_fatal_signal_set): New function.
* lib/clean-temp.c: Include asyncsafe-spin.h, gl_linked_list.h.
(struct closeable_fd): New type.
(fatal_signal_set): New variable.
(init_fatal_signal_set): New function.
(asyncsafe_close, asyncsafe_fclose_variant): New functions.
(cleanup_action): Invoke asyncsafe_close instead of close.
(create_temp_dir): Invoke init_fatal_signal_set.
(register_fd): Use a plain linked list. Add a 'struct closeable_fd *'
element.
(unregister_fd): Remove function.
(close_temp): Cleanup descriptors list on the fly. Invoke
init_fatal_signal_set. Invoke asyncsafe_close instead of close.
(fclose_variant_temp): New function.
(fclose_temp, fwriteerror_temp, close_stream_temp): Use it.
* modules/clean-temp (Depends-on): Add asyncsafe-spin, linked-list.
2020-07-04 Bruno Haible <bruno@clisp.org>
clean-temp: Make multithread-safe, part 1.
* lib/clean-temp.c: Include glthread/lock.h.
(cleanup_list_lock): New variable.
(register_temp_file, unregister_temp_file, register_temp_subdir,
unregister_temp_subdir, cleanup_temp_dir_contents): Use it.
(create_temp_dir): Likewise. Don't free the old array.
(descriptors_lock): New variable.
(register_fd, unregister_fd): Use it.
* modules/clean-temp (Depends-on): Add lock.
0001-clean-temp-Make-multithread-safe-part-1.patch
Description: Text Data
0002-clean-temp-Make-multithread-safe-part-2.patch
Description: Text Data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- clean-temp: make multithread-safe,
Bruno Haible <=