mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-25 01:37:22 +00:00
Merge branch 'bugfix/pthread_docs' into 'master'
Fix and improve pthread docs, create pthread example Closes IDF-731 and IDFGH-5085 See merge request espressif/esp-idf!13314
This commit is contained in:
@@ -66,7 +66,7 @@ typedef struct {
|
||||
|
||||
|
||||
static SemaphoreHandle_t s_threads_mux = NULL;
|
||||
static portMUX_TYPE s_mutex_init_lock = portMUX_INITIALIZER_UNLOCKED;
|
||||
portMUX_TYPE pthread_lazy_init_lock = portMUX_INITIALIZER_UNLOCKED; // Used for mutexes and cond vars
|
||||
static SLIST_HEAD(esp_thread_list_head, esp_pthread_entry) s_threads_list
|
||||
= SLIST_HEAD_INITIALIZER(s_threads_list);
|
||||
static pthread_key_t s_pthread_cfg_key;
|
||||
@@ -585,6 +585,10 @@ int pthread_mutex_destroy(pthread_mutex_t *mutex)
|
||||
if (!mutex) {
|
||||
return EINVAL;
|
||||
}
|
||||
if ((intptr_t) *mutex == PTHREAD_MUTEX_INITIALIZER) {
|
||||
return 0; // Static mutex was never initialized
|
||||
}
|
||||
|
||||
mux = (esp_pthread_mutex_t *)*mutex;
|
||||
if (!mux) {
|
||||
return EINVAL;
|
||||
@@ -638,11 +642,11 @@ static int pthread_mutex_init_if_static(pthread_mutex_t *mutex)
|
||||
{
|
||||
int res = 0;
|
||||
if ((intptr_t) *mutex == PTHREAD_MUTEX_INITIALIZER) {
|
||||
portENTER_CRITICAL(&s_mutex_init_lock);
|
||||
portENTER_CRITICAL(&pthread_lazy_init_lock);
|
||||
if ((intptr_t) *mutex == PTHREAD_MUTEX_INITIALIZER) {
|
||||
res = pthread_mutex_init(mutex, NULL);
|
||||
}
|
||||
portEXIT_CRITICAL(&s_mutex_init_lock);
|
||||
portEXIT_CRITICAL(&pthread_lazy_init_lock);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -728,6 +732,7 @@ int pthread_mutexattr_init(pthread_mutexattr_t *attr)
|
||||
if (!attr) {
|
||||
return EINVAL;
|
||||
}
|
||||
memset(attr, 0, sizeof(*attr));
|
||||
attr->type = PTHREAD_MUTEX_NORMAL;
|
||||
attr->is_initialized = 1;
|
||||
return 0;
|
||||
@@ -769,6 +774,7 @@ int pthread_attr_init(pthread_attr_t *attr)
|
||||
{
|
||||
if (attr) {
|
||||
/* Nothing to allocate. Set everything to default */
|
||||
memset(attr, 0, sizeof(*attr));
|
||||
attr->stacksize = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT;
|
||||
attr->detachstate = PTHREAD_CREATE_JOINABLE;
|
||||
return 0;
|
||||
@@ -778,13 +784,8 @@ int pthread_attr_init(pthread_attr_t *attr)
|
||||
|
||||
int pthread_attr_destroy(pthread_attr_t *attr)
|
||||
{
|
||||
if (attr) {
|
||||
/* Nothing to deallocate. Reset everything to default */
|
||||
attr->stacksize = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT;
|
||||
attr->detachstate = PTHREAD_CREATE_JOINABLE;
|
||||
return 0;
|
||||
}
|
||||
return EINVAL;
|
||||
/* Nothing to deallocate. Reset everything to default */
|
||||
return pthread_attr_init(attr);
|
||||
}
|
||||
|
||||
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
|
||||
|
Reference in New Issue
Block a user