In virtual all cases involving updates of non-interlocked data
structures, the logic is -- and must be:
for (;;)
{
<examine state making tentative decision and computer desired
future state>
if (<state incompatible with operation>)
<punt>
if (<interlocked compare and swap>)
<success -- break out of loop or whatever>
}
About the only exceptions are interlocked increment and decrement for
very simple operations. Whether or not there actually is an
"interlocked or" primitive, it isn't useful because it tell you nothing
about the flag state before the operation.
Maintaining non-interlocked data structures is the hardest part of
software engineering. Very few engineers can do it well. Ironically,
it is considered hard only by the folks proficient at it.
I submit that Firebird would be well advised to restrict interlocked
primitives to interlocked increment, interlock decrement, and
interlocked compare and swap and to write all but the most trivial
increment and decrement as stylized interlock compare and swap loops.
On 12/8/2015 9:31 AM, Vlad Khorsun wrote:
08.12.2015 16:09, Dimitry Sibiryakov wrote:
08.12.2015 14:56, Vlad Khorsun wrote:
Do you see the principal difference with Firebird asm code i show ?
Principal difference - no. Size difference - yes.
If we will support all existing intrinsic - do you think our code will be
smaller ? I speak about AtomicCounter class.
Do you see the loop with compare_exchange ?
Yes.
Do you see the "lock or" operation ?
Yes.
I speak about case when return value *is used* by caller. Code in link
make two calls of "atomic or", later one is not relevant here.
Do you still have questions ?
Yes: why to write 6 lines of code instead of two?
if ((dbb_flags.interlockedOr(DBB_sweep_starting) & (DBB_sweep_in_progress |
DBB_sweep_starting))
|| (dbb_ast_flags & DBB_shutdown))
return false;
This code is not the same as code that you blamed and it is not correct at
all.
Regards,
Vlad
------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
Firebird-Devel mailing list, web interface at
https://lists.sourceforge.net/lists/listinfo/firebird-devel
------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
Firebird-Devel mailing list, web interface at
https://lists.sourceforge.net/lists/listinfo/firebird-devel