You copied the Doc URL to your clipboard.

Mutexes [ALPHA]

The C++ Thread Porting API provides mutex functions in the <arm-tpl.h> header file.

Note

This topic describes an [ALPHA] feature. See Support level definitions.

Types

struct __ARM_TPL_mutex_t {  
    _Atomic uintptr_t data;
};

Functions

int __ARM_TPL_recursive_mutex_init(__ARM_TPL_mutex_t* __m);
int __ARM_TPL_mutex_lock(__ARM_TPL_mutex_t* __m);
int __ARM_TPL_mutex_trylock(__ARM_TPL_mutex_t* __m);
int __ARM_TPL_mutex_unlock(__ARM_TPL_mutex_t* __m);
int __ARM_TPL_mutex_destroy(__ARM_TPL_mutex_t* __m);

Usage

The API uses the __ARM_TPL_mutex_t type to encapsulate a pointer to an underlying platform-specific mutex type. The semantics of these functions are:

  • The functions __ARM_TPL_mutex_lock() and __ARM_TPL_mutex_trylock() must operate on an initialize-on-first-use basis with respect to __m->data. If the value __m->data is zero, an implementation must first initialize __m->data to point to a valid platform mutex before carrying out the requested locking operation. This initialization must be thread-safe. For more information, see Thread-safe initialization of Mutexes and Condition variables [ALPHA].
  • The function __ARM_TPL_mutex_lock() must lock the mutex represented at __m, blocking the calling thread until the mutex becomes available. If the function is successful, it must return zero, with the calling thread as the owner of the underlying mutex. If the function is not successful, it must return non-zero.
  • The function __ARM_TPL_mutex_trylock() is similar to __ARM_TPL_mutex_lock(), except if the mutex at __m is already locked, it must return immediately unsuccessfully. If the function successfully performs the lock, it must return zero. Otherwise, it must return non-zero.
  • The function __ARM_TPL_mutex_unlock() and __ARM_TPL_mutex_destroy() must return zero if the value __m->data is zero. Otherwise, they must perform the requested operation on the platform mutex pointed to by __m->data and then return zero if successful, or return non-zero if not successful.
  • The function __ARM_TPL_mutex_unlock() must unlock the mutex represented at __m. If the mutex at __m was initialized as a recursive mutex, it is unlocked only when the lock count reaches zero. This function must return zero if successful, or return non-zero if not successful.
  • The function __ARM_TPL_mutex_destroy() must destroy the mutex represented at __m. It is guaranteed that an already destroyed __ARM_TPL_mutex_t object is not re-referenced through any API functions afterward. __ARM_TPL_mutex_destroy() must return zero if successful, or return non-zero if not successful.
  • The function __ARM_TPL_recursive_mutex_init() must initialize the platform mutex pointed to by__m->data as a recursive mutex. There is no requirement for this initialization to be thread-safe. This function must return zero if successful, or non-zero if not successful.

Returns

These functions must return zero if successful, or return non-zero if not successful to indicate an error.

Was this page helpful? Yes No