Add minimal thread-safety to BFD
authorTom Tromey <tom@tromey.com>
Wed, 6 Sep 2023 01:05:40 +0000 (19:05 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 8 Nov 2023 00:47:16 +0000 (17:47 -0700)
commit1185b5b79a12ba67eb60bee3f75babf7a222fde0
tree8bec5accb1289ea191ae245815adcbd6e7f0df8d
parentc6d6a048f5a6f422e470c7c4bdb21a0c59d7c8fd
Add minimal thread-safety to BFD

This patch provides some minimal thread-safety to BFD.

The BFD client can request thread-safety by providing a lock and
unlock function.  The globals used during BFD creation (e.g.,
bfd_id_counter) are then locked, and the file descriptor cache is also
locked.  A function to clean up any thread-local data is now provided
for BFD clients.

* bfd-in2.h: Regenerate.
* bfd.c (lock_fn, unlock_fn): New globals.
(bfd_thread_init, bfd_thread_cleanup, bfd_lock, bfd_unlock): New
functions.
* cache.c (bfd_cache_lookup_worker): Use _bfd_open_file_unlocked.
(cache_btell, cache_bseek, cache_bread, cache_bwrite): Lock
and unlock.
(cache_bclose): Add comment.
(cache_bflush, cache_bstat, cache_bmmap): Lock and unlock.
(_bfd_cache_init_unlocked): New function.
(bfd_cache_init): Use it.  Lock and unlock.
(_bfd_cache_close_unlocked): New function.
(bfd_cache_close, bfd_cache_close_all): Use it.  Lock and unlock.
(_bfd_open_file_unlocked): New function.
(bfd_open_file): Use it.  Lock and unlock.
* doc/bfd.texi (BFD front end): Add Threading menu item.
* libbfd.h: Regenerate.
* opncls.c (_bfd_new_bfd): Lock and unlock.
* po/bfd.pot: Regenerate.
bfd/bfd-in2.h
bfd/bfd.c
bfd/cache.c
bfd/doc/bfd.texi
bfd/libbfd.h
bfd/opncls.c
bfd/po/bfd.pot