@@ -405,7 +405,7 @@ \subsection{Test and set}
405
405
\clang {} and \cplusplus {} offer a type dedicated to this purpose, called \monobox {atomic\_ flag}.
406
406
We could use it to build a simple spinlock:
407
407
\label {spinlock }
408
- \begin {cppcode }
408
+ \begin {ccode }
409
409
atomic_flag af = ATOMIC_FLAG_INIT;
410
410
411
411
void lock()
@@ -414,7 +414,7 @@ \subsection{Test and set}
414
414
}
415
415
416
416
void unlock() { atomic_flag_clear(&af); }
417
- \end {cppcode }
417
+ \end {ccode }
418
418
If we call \cc |lock()| and the previous value is \cc |false|,
419
419
we are the first to acquire the lock,
420
420
and can proceed with exclusive access to whatever the lock protects.
@@ -555,7 +555,7 @@ \section{Sequential consistency on weakly-ordered hardware}
555
555
Other systems programming languages like D and Rust have converged on similar models.}
556
556
Let's examine \textsc {Arm}, since it is both popular and straightforward.
557
557
Consider the simplest atomic operations: loads and stores.
558
- Given some \cpp |atomic_int foo|,
558
+ Given some \cc |atomic_int foo|,
559
559
\newline
560
560
% Shield your eyes.
561
561
% Essentially,
@@ -564,12 +564,12 @@ \section{Sequential consistency on weakly-ordered hardware}
564
564
% 3. In the middle, place an arrow for each (futzing with height a bit)
565
565
% with the text "becomes" over it.
566
566
\begin {minipage }{0.35\linewidth }
567
- \begin {cppcode }
567
+ \begin {ccode }
568
568
int getFoo()
569
569
{
570
570
return foo;
571
571
}
572
- \end {cppcode }
572
+ \end {ccode }
573
573
\end {minipage }
574
574
\raisebox {-1ex}{
575
575
\begin {tikzpicture }
@@ -588,12 +588,12 @@ \section{Sequential consistency on weakly-ordered hardware}
588
588
\end {minipage }
589
589
% Similarly,
590
590
\begin {minipage }{0.35\linewidth }
591
- \begin {cppcode }
591
+ \begin {ccode }
592
592
void setFoo(int i)
593
593
{
594
594
foo = i;
595
595
}
596
- \end {cppcode }
596
+ \end {ccode }
597
597
\end {minipage }
598
598
\raisebox {-1ex}{
599
599
\begin {tikzpicture }
@@ -631,9 +631,9 @@ \section{Implementing atomic read-modify-write operations with LL/SC instruction
631
631
This mechanism is illustrated through an atomic fetch and add example.
632
632
633
633
On \textsc {Arm},
634
- \begin {cppcode }
634
+ \begin {ccode }
635
635
void incFoo() { ++foo; }
636
- \end {cppcode }
636
+ \end {ccode }
637
637
compiles to:
638
638
\ begin{lstlisting} [language={[ARM]Assembler}]
639
639
incFoo:
@@ -759,9 +759,7 @@ \section{Memory orderings}
759
759
\begin {cppcode }
760
760
void lock()
761
761
{
762
- while (af.test_and_set(memory_order_acquire)) {
763
- /* wait */
764
- }
762
+ while (af.test_and_set(memory_order_acquire)) { /* wait */ }
765
763
}
766
764
767
765
void unlock()
0 commit comments