Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b26cfc48 authored by pierre Kuo's avatar pierre Kuo Committed by Paul E. McKenney
Browse files

doc: Update control-dependencies section of memory-barriers.txt



In the following example, if MAX is defined to be 1, then the compiler
knows (Q % MAX) is equal to zero.  The compiler can therefore throw
away the "then" branch (and the "if"), retaining only the "else" branch.

	q = READ_ONCE(a);
	if (q % MAX) {
		WRITE_ONCE(b, 1);
		do_something();
	} else {
		WRITE_ONCE(b, 2);
		do_something_else();
	}

It is therefore necessary to modify the example like this:

        q = READ_ONCE(a);
-       WRITE_ONCE(b, 1);
+       WRITE_ONCE(b, 2);
        do_something_else();

Signed-off-by: default avatarpierre Kuo <vichy.kuo@gmail.com>
Acked-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
parent d3d3a3cc
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -768,7 +768,7 @@ equal to zero, in which case the compiler is within its rights to
transform the above code into the following:
transform the above code into the following:


	q = READ_ONCE(a);
	q = READ_ONCE(a);
	WRITE_ONCE(b, 1);
	WRITE_ONCE(b, 2);
	do_something_else();
	do_something_else();


Given this transformation, the CPU is not required to respect the ordering
Given this transformation, the CPU is not required to respect the ordering