The __strex intrinsic lets you use an STREX[size] instruction in your C or C++ code to store data to memory.
Note
This intrinsic is deprecated.
Note
The compiler does not guarantee to preserve the state of the exclusive
monitor. It might generate load and store instructions between the LDREX instruction generated for the __ldrex
intrinsic and the STREX instruction generated for the
__strex intrinsic. Because memory accesses can clear the
exclusive monitor, code using the __ldrex and __strex intrinsics can have unexpected behavior. Where LDREX and STREX instructions are
needed, ARM recommends using embedded assembly.
Syntax
int __strex(unsigned int val, volatile void
*ptr)
Where:
val
is the value to be written to memory.
ptr
points to the address of the data to be written to in memory. To specify the size
of the data to be written, cast the parameter to an appropriate integral type.
Table 9-11 Access widths that the __strex intrinsic supports
Instruction
Size of data stored
Pointer type
STREXB
byte
char *
STREXH
halfword
short *
STREX
word
int *
Return value
The __strex intrinsic returns:
0
if the STREX instruction succeeds
1
if the STREX instruction is locked out.
Errors
The compiler does not recognize the __strex intrinsic when compiling for a
target that does not support the STREX instruction. The compiler generates
either a warning or an error in this case, depending on the source language:
In C code: Warning: #223-D: function "__strex" declared implicitly.
In C++ code: Error: #20: identifier "__strex" is undefined.
The __strex intrinsic does not support access to doubleword data. The
compiler generates an error if you specify an access width that is not supported.
Example
int foo(void)
{
int loc=0xff;
return(!__strex(0x20, (volatile char *)loc));
}
Compiling this code with the command-line option --cpu=6k produces
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.