@@ -405,7 +405,7 @@ \subsection{Test and set}
405405\clang {} and \cplusplus {} offer a type dedicated to this purpose, called \monobox {atomic\_ flag}.
406406We could use it to build a simple spinlock:
407407\label {spinlock }
408- \begin {cppcode }
408+ \begin {ccode }
409409atomic_flag af = ATOMIC_FLAG_INIT;
410410
411411void lock()
@@ -414,7 +414,7 @@ \subsection{Test and set}
414414}
415415
416416void unlock() { atomic_flag_clear(&af); }
417- \end {cppcode }
417+ \end {ccode }
418418If we call \cc |lock()| and the previous value is \cc |false|,
419419we are the first to acquire the lock,
420420and can proceed with exclusive access to whatever the lock protects.
@@ -555,7 +555,7 @@ \section{Sequential consistency on weakly-ordered hardware}
555555Other systems programming languages like D and Rust have converged on similar models.}
556556Let's examine \textsc {Arm}, since it is both popular and straightforward.
557557Consider the simplest atomic operations: loads and stores.
558- Given some \cpp |atomic_int foo|,
558+ Given some \cc |atomic_int foo|,
559559\newline
560560% Shield your eyes.
561561% Essentially,
@@ -564,12 +564,12 @@ \section{Sequential consistency on weakly-ordered hardware}
564564% 3. In the middle, place an arrow for each (futzing with height a bit)
565565% with the text "becomes" over it.
566566\begin {minipage }{0.35\linewidth }
567- \begin {cppcode }
567+ \begin {ccode }
568568int getFoo()
569569{
570570 return foo;
571571}
572- \end {cppcode }
572+ \end {ccode }
573573\end {minipage }
574574\raisebox {-1ex}{
575575\begin {tikzpicture }
@@ -588,12 +588,12 @@ \section{Sequential consistency on weakly-ordered hardware}
588588\end {minipage }
589589% Similarly,
590590\begin {minipage }{0.35\linewidth }
591- \begin {cppcode }
591+ \begin {ccode }
592592void setFoo(int i)
593593{
594594 foo = i;
595595}
596- \end {cppcode }
596+ \end {ccode }
597597\end {minipage }
598598\raisebox {-1ex}{
599599\begin {tikzpicture }
@@ -631,9 +631,9 @@ \section{Implementing atomic read-modify-write operations with LL/SC instruction
631631This mechanism is illustrated through an atomic fetch and add example.
632632
633633On \textsc {Arm},
634- \begin {cppcode }
634+ \begin {ccode }
635635void incFoo() { ++foo; }
636- \end {cppcode }
636+ \end {ccode }
637637compiles to:
638638\ begin{lstlisting} [language={[ARM]Assembler}]
639639incFoo:
@@ -759,9 +759,7 @@ \section{Memory orderings}
759759\begin {cppcode }
760760void lock()
761761{
762- while (af.test_and_set(memory_order_acquire)) {
763- /* wait */
764- }
762+ while (af.test_and_set(memory_order_acquire)) { /* wait */ }
765763}
766764
767765void unlock()
0 commit comments