linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #01730
[Bug 617591] Re: Pointer.h/intrusive_ptr_base class is too heavy-weight
We use safeInc/Dec for different purposes:
1. reference counting in smart pointers
2. BufferedSocket - counting for "sockets" variable
3. Client.h/struct Counts - for just counters which incremented/decremented from different threads
My patch is for (1) only. It uses atomic counter which was designed
exactly for this purpose - reference counting in smart pointers (it has
necessary memory barriers in case it reaches zero).
For (2) - in current code I think we also can use the same atomic_count,
since we do some action when "sockets" variable reaches zero. But if
sometimes we will use it in form like "if (sockets==1) do_something()",
it will not be safe.
For (3) it is not obviously immediately, if we can replace it with
atomic counter, since memory barriers may be necessary.
As you can see, we use safeInc/Dec for different purposes, so it may
require different "optimized" implementations. For (1), it is very
straightforward, for other cases it is not.
--
Pointer.h/intrusive_ptr_base class is too heavy-weight
https://bugs.launchpad.net/bugs/617591
You received this bug notification because you are a member of LinuxDC++
Team, which is subscribed to LinuxDC++.
Status in DC++: New
Status in Linux DC++: Confirmed
Bug description:
"Pointer.h/intrusive_ptr_base" class is too heavy-weight (at least on unix), it uses pthread mutex for every increment/decrement. And since this mutex is static (Thread::mtx), it leads to bad concurrency even for independent intrusive pointers.
Patch attached, which uses portable atomic reference counters from boost.
It uses boost::detail::atomic_count from shared_ptr, so it may theoretically change in future (since it is in detail), but I doubt it will.
References