tests: posix: mutex: init and destroy mutexattr properly

Previously, the mutex attribute was not initialized prior to its
first use or subsequently destroyed.

Ensure that it is initialized by calling
pthread_mutexattr_init() and destroyed by calling
pthread_mutexattr_destroy().

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This commit is contained in:
Christopher Friedt 2024-02-18 10:45:33 -05:00 committed by Chris Friedt
parent 7645890af6
commit 986e8f0ac4
1 changed files with 3 additions and 1 deletions

View File

@ -49,11 +49,12 @@ static void test_mutex_common(int type, void *(*entry)(void *arg))
pthread_t th;
int protocol;
int actual_type;
pthread_mutexattr_t mut_attr;
struct sched_param schedparam;
pthread_mutexattr_t mut_attr = {0};
schedparam.sched_priority = 2;
zassert_ok(pthread_mutexattr_init(&mut_attr));
zassert_ok(pthread_mutexattr_settype(&mut_attr, type), "setting mutex type is failed");
zassert_ok(pthread_mutex_init(&mutex, &mut_attr), "mutex initialization is failed");
@ -61,6 +62,7 @@ static void test_mutex_common(int type, void *(*entry)(void *arg))
"reading mutex type is failed");
zassert_ok(pthread_mutexattr_getprotocol(&mut_attr, &protocol),
"reading mutex protocol is failed");
zassert_ok(pthread_mutexattr_destroy(&mut_attr));
zassert_ok(pthread_mutex_lock(&mutex));