[Rpm-maint] [rpm-software-management/rpm] Turn nrefs into atomic_int (PR #3370)
Florian Festi
notifications at github.com
Fri Oct 11 06:39:16 UTC 2024
Throughout the code base reference counting is done in a thread-unsave way. A few places use the content lock (aka mutex) to also protect the reference counter. This is wrong and complicates freeing interconnected data structures. This lock should only protect the content of the instance.
Turn all nrefs members into atomic_int so they are thread-save themselves.
Make sure to only use ++ and -- operators and avoid non atomic combinations of reading and writing. Drop all the static *Unlink functions that are involved in this.
Make sure the data lock is not aquired while updating the nrefs members.
Technically the *Free() functions should *Link() the instance after the ref count has reached 0 and the decision to free it has been made. Otherwise the cleanup code linking and freeing to will lead to a recusions. Right now only rpmts needs that. SO it is omitted everywhere else.
FD_t is special in that fdFree return the instance after free iff it still has not reached a ref count of 0. Unfortunately code in rpmShowProgress() relies on that.
This does not make the data structures thread save on its own. But it gives a foundation on which data locking can be implemented.
You can view, comment on, or merge this pull request online at:
https://github.com/rpm-software-management/rpm/pull/3370
-- Commit Summary --
* Turn nrefs into atomic_int
-- File Changes --
M lib/backend/dbi.hh (3)
M lib/header.cc (14)
M lib/psm.cc (3)
M lib/rpmdb.cc (16)
M lib/rpmds.cc (15)
M lib/rpmfi.cc (32)
M lib/rpmprob.cc (19)
M lib/rpmps.cc (20)
M lib/rpmts.cc (15)
M lib/rpmts_internal.hh (3)
M rpmio/rpmio.cc (23)
M rpmio/rpmkeyring.cc (41)
M rpmio/rpmstrpool.cc (31)
-- Patch Links --
https://github.com/rpm-software-management/rpm/pull/3370.patch
https://github.com/rpm-software-management/rpm/pull/3370.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3370
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/pull/3370 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20241010/0411a638/attachment.html>
More information about the Rpm-maint
mailing list