FreeRTOS / Lab-Project-FreeRTOS-POSIX

This repository contains FreeRTOS+POSIX source code, which could be consumed as a submodule.
MIT License
95 stars 60 forks source link

Not compling FREERTOS_POSIX_MUTEX_INITIALIZER #18

Closed snahmad closed 2 years ago

snahmad commented 2 years ago

define FREERTOS_POSIX_MUTEX_INITIALIZER \

( ( ( pthread_mutex_internal_t )         \
{                                        \
    .xIsInitialized = pdFALSE,           \
    .xMutex = { { 0 } },                 \
    .xTaskOwner = NULL,                  \
    .xAttr = { .iType = 0 }              \
}                                        \
    )                                    \
)

FreeRTOS_POSIX_internal.h:64:5: error: incompatible types when initializing type 'long unsigned int' using type 'pthread_mutex_internal_t' {aka 'struct pthread_mutex_internal'}

dachalco commented 2 years ago

Hi @snahmad

  1. Is this FREERTOS_POSIX_MUTEX_INITIALIZER being used in the application code?
  2. Which FreeRTOS port and compiler are you using?

The only use case of FREERTOS_POSIX_MUTEX_INITIALIZER in the +POSIX code is at FreeRTOS_POSIX_pthread_mutex.c#L126, but it's correctly used for assigning to a pthread_mutex_internal_t type, hence why I wonder whether the macro has been used elsewhere in the app.

ravibhagavandas commented 2 years ago

As @dachalco pointed, is this error coming from a usage of the initializer in application code ? If so can you show how is it being used ? FREERTOS_POSIX_MUTEX_INITIALIZER is supposed to be an internal macro and should not be used in application code (hence defined in FreeRTOS_POSIX_internal.h). The correct usage should be to use PTHREAD_MUTEX_INITIALIZER as shown in the test example below:

https://github.com/aws/amazon-freertos/blob/dcbe7a6553bca8a4ae3f5a93aaf737aa64214e88/libraries/freertos_plus/standard/freertos_plus_posix/test/iot_test_posix_pthread.c#L711

ravibhagavandas commented 2 years ago

I will close the issue due to inactivity. Please open an issue if you still have issues.