How to initialize a mutex statically on WICED platform?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
SeSh_3921701
Level 1
Level 1

Hi!

There's some part of the code I'm dealing with that needs the mutex to be initialized statically:

static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

Is there any way to recreate such thing on WICED platform?

I have included wiced_rtos.h to have access to the wiced_mutex_t definition and added appropriate typedef:

typedef wiced_mutex_t pthread_mutex_t;

Header inclusion and typedef work fine, but static mutex initialization gives the error about undeclared PTHREAD_MUTEX_INITIALIZER.

Thanks in advance for the response!

0 Likes
1 Solution

Hello,

The macro PTHREAD_MUTEX_INITIALIZER is used to initialize the mutex in a POSIX compatible system. In WICED, we have ThreadX and FreeRTOS Operating system. These RTOS do not have POSIX wrappers to determine the value of PTHREAD_MUTEX_INITIALIZER. You could include the POSIX wrappers for FreeRTOS in WICED and give it a try.

FYI: This link will be helpful FreeRTOS+POSIX 

View solution in original post

4 Replies
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Can you please tell what the value of PTHREAD_MUTEX_INITIALIZER is and where is it initialized?

0 Likes

Hi!

I think its value is platform-dependent like in one case it can be initialized to some predefined value, like 0xFFFFFFFF, in another case it is a macro that is resolved to some kind of structure initialization values. And as a consequence, it isn't initialized anywhere, instead, it is an initializer by itself.

I'm wondering if there's such thing on WICED platform in general.

Thanks.

0 Likes

Hello,

The macro PTHREAD_MUTEX_INITIALIZER is used to initialize the mutex in a POSIX compatible system. In WICED, we have ThreadX and FreeRTOS Operating system. These RTOS do not have POSIX wrappers to determine the value of PTHREAD_MUTEX_INITIALIZER. You could include the POSIX wrappers for FreeRTOS in WICED and give it a try.

FYI: This link will be helpful FreeRTOS+POSIX 

Hi, riya!

Thanks for the link, will check and give it a try.

0 Likes