3.2.3 __ldrex and __strex intrinsics deprecated

The __ldrex and __strex family of intrinsics have been deprecated, and use of the LDREX and STREX family of instructions in inline assembly code has also been deprecated.

Use one of the following alternatives:

For example, the following code uses the deprecated __ldrex and __strex intrinsics to implement a mutex lock, preventing concurrent processes from writing to output at the same time:

#define LOCKED 1
#define UNLOCKED 0

static int output_mutex = UNLOCKED;

void lock_mutex(void) {
  int status;
  do {
    status = __ldrex(&output_mutex);
  } while(status == LOCKED || __strex(LOCKED, &output_mutex) );
}

void unlock_mutex() {
  output_mutex = UNLOCKED;
}

void output_string(char * str)
{
  int i;
  /* Wait until the output mutex lock is acquired */
  lock_mutex();

  /* Output each character in turn */
  for(i=0 ; str[i] != '\0' ; i++) {
    putc(str[i], stdout);
  }

  /* Release output mutex lock */
  unlock_mutex();
}

The locking mechanism lock_mutex() can be refactored to use the __sync_* family of GNU built-in functions as follows:

void lock_mutex(void) {
  while (!__sync_bool_compare_and_swap(&output_mutex, UNLOCKED, LOCKED)) {};
}
Non-ConfidentialPDF file icon PDF versionARM DUI0530M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.