Rename mutex->is_valid to mutex->state
Rename struct member to make it more representative of its current use. Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
3774637518
commit
9e25936241
2 changed files with 11 additions and 11 deletions
|
@ -29,12 +29,12 @@ extern "C" {
|
||||||
typedef struct mbedtls_threading_mutex_t {
|
typedef struct mbedtls_threading_mutex_t {
|
||||||
pthread_mutex_t MBEDTLS_PRIVATE(mutex);
|
pthread_mutex_t MBEDTLS_PRIVATE(mutex);
|
||||||
|
|
||||||
/* WARNING - is_valid should only be accessed when holding the mutex lock in
|
/* WARNING - state should only be accessed when holding the mutex lock in
|
||||||
* tests/src/threading_helpers.c, otherwise corruption can occur.
|
* tests/src/threading_helpers.c, otherwise corruption can occur.
|
||||||
* is_valid will be 0 after a failed init or a free, and nonzero after a
|
* state will be 0 after a failed init or a free, and nonzero after a
|
||||||
* successful init. This field is for testing only and thus not considered
|
* successful init. This field is for testing only and thus not considered
|
||||||
* part of the public API of Mbed TLS and may change without notice.*/
|
* part of the public API of Mbed TLS and may change without notice.*/
|
||||||
char MBEDTLS_PRIVATE(is_valid);
|
char MBEDTLS_PRIVATE(state);
|
||||||
|
|
||||||
} mbedtls_threading_mutex_t;
|
} mbedtls_threading_mutex_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -58,8 +58,8 @@
|
||||||
* indicate the exact location of the problematic call. To locate the error,
|
* indicate the exact location of the problematic call. To locate the error,
|
||||||
* use a debugger and set a breakpoint on mbedtls_test_mutex_usage_error().
|
* use a debugger and set a breakpoint on mbedtls_test_mutex_usage_error().
|
||||||
*/
|
*/
|
||||||
enum value_of_mutex_is_valid_field {
|
enum value_of_mutex_state_field {
|
||||||
/* Potential values for the is_valid field of mbedtls_threading_mutex_t.
|
/* Potential values for the state field of mbedtls_threading_mutex_t.
|
||||||
* Note that MUTEX_FREED must be 0 and MUTEX_IDLE must be 1 for
|
* Note that MUTEX_FREED must be 0 and MUTEX_IDLE must be 1 for
|
||||||
* compatibility with threading_mutex_init_pthread() and
|
* compatibility with threading_mutex_init_pthread() and
|
||||||
* threading_mutex_free_pthread(). MUTEX_LOCKED could be any nonzero
|
* threading_mutex_free_pthread(). MUTEX_LOCKED could be any nonzero
|
||||||
|
@ -117,12 +117,12 @@ static void mbedtls_test_wrap_mutex_free(mbedtls_threading_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
||||||
|
|
||||||
switch (mutex->is_valid) {
|
switch (mutex->state) {
|
||||||
case MUTEX_FREED:
|
case MUTEX_FREED:
|
||||||
mbedtls_test_mutex_usage_error(mutex, "free without init or double free");
|
mbedtls_test_mutex_usage_error(mutex, "free without init or double free");
|
||||||
break;
|
break;
|
||||||
case MUTEX_IDLE:
|
case MUTEX_IDLE:
|
||||||
mutex->is_valid = MUTEX_FREED;
|
mutex->state = MUTEX_FREED;
|
||||||
--live_mutexes;
|
--live_mutexes;
|
||||||
break;
|
break;
|
||||||
case MUTEX_LOCKED:
|
case MUTEX_LOCKED:
|
||||||
|
@ -145,13 +145,13 @@ static int mbedtls_test_wrap_mutex_lock(mbedtls_threading_mutex_t *mutex)
|
||||||
* condition. */
|
* condition. */
|
||||||
int ret = mutex_functions.lock(mutex);
|
int ret = mutex_functions.lock(mutex);
|
||||||
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
||||||
switch (mutex->is_valid) {
|
switch (mutex->state) {
|
||||||
case MUTEX_FREED:
|
case MUTEX_FREED:
|
||||||
mbedtls_test_mutex_usage_error(mutex, "lock without init");
|
mbedtls_test_mutex_usage_error(mutex, "lock without init");
|
||||||
break;
|
break;
|
||||||
case MUTEX_IDLE:
|
case MUTEX_IDLE:
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
mutex->is_valid = MUTEX_LOCKED;
|
mutex->state = MUTEX_LOCKED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MUTEX_LOCKED:
|
case MUTEX_LOCKED:
|
||||||
|
@ -173,7 +173,7 @@ static int mbedtls_test_wrap_mutex_unlock(mbedtls_threading_mutex_t *mutex)
|
||||||
* change the state is to hold the passed in and internal mutex - otherwise
|
* change the state is to hold the passed in and internal mutex - otherwise
|
||||||
* we create a race condition. */
|
* we create a race condition. */
|
||||||
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
||||||
switch (mutex->is_valid) {
|
switch (mutex->state) {
|
||||||
case MUTEX_FREED:
|
case MUTEX_FREED:
|
||||||
mbedtls_test_mutex_usage_error(mutex, "unlock without init");
|
mbedtls_test_mutex_usage_error(mutex, "unlock without init");
|
||||||
break;
|
break;
|
||||||
|
@ -181,7 +181,7 @@ static int mbedtls_test_wrap_mutex_unlock(mbedtls_threading_mutex_t *mutex)
|
||||||
mbedtls_test_mutex_usage_error(mutex, "unlock without lock");
|
mbedtls_test_mutex_usage_error(mutex, "unlock without lock");
|
||||||
break;
|
break;
|
||||||
case MUTEX_LOCKED:
|
case MUTEX_LOCKED:
|
||||||
mutex->is_valid = MUTEX_IDLE;
|
mutex->state = MUTEX_IDLE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue