feat(pthread): modify for ESP8266

1. remove "IRAM_ATTR" from pthread function
2. modify "critical" function
3. remove SMP function
4. add platform support
This commit is contained in:
dongheng
2019-08-27 10:33:38 +08:00
parent 8cf028873d
commit 24e53102bf
10 changed files with 170 additions and 84 deletions

View File

@ -42,8 +42,6 @@ typedef struct key_entry_t_ {
// List of all keys created with pthread_key_create()
SLIST_HEAD(key_list_t, key_entry_t_) s_keys = SLIST_HEAD_INITIALIZER(s_keys);
static portMUX_TYPE s_keys_lock = portMUX_INITIALIZER_UNLOCKED;
// List of all value entries associated with a thread via pthread_setspecific()
typedef struct value_entry_t_ {
pthread_key_t key;
@ -62,7 +60,7 @@ int pthread_key_create(pthread_key_t *key, pthread_destructor_t destructor)
return ENOMEM;
}
portENTER_CRITICAL(&s_keys_lock);
portENTER_CRITICAL();
const key_entry_t *head = SLIST_FIRST(&s_keys);
new_key->key = (head == NULL) ? 1 : (head->key + 1);
@ -71,27 +69,27 @@ int pthread_key_create(pthread_key_t *key, pthread_destructor_t destructor)
SLIST_INSERT_HEAD(&s_keys, new_key, next);
portEXIT_CRITICAL(&s_keys_lock);
portEXIT_CRITICAL();
return 0;
}
static key_entry_t *find_key(pthread_key_t key)
{
portENTER_CRITICAL(&s_keys_lock);
portENTER_CRITICAL();
key_entry_t *result = NULL;;
SLIST_FOREACH(result, &s_keys, next) {
if(result->key == key) {
break;
}
}
portEXIT_CRITICAL(&s_keys_lock);
portEXIT_CRITICAL();
return result;
}
int pthread_key_delete(pthread_key_t key)
{
portENTER_CRITICAL(&s_keys_lock);
portENTER_CRITICAL();
/* Ideally, we would also walk all tasks' thread local storage value_list here
and delete any values associated with this key. We do not do this...
@ -103,7 +101,7 @@ int pthread_key_delete(pthread_key_t key)
free(entry);
}
portEXIT_CRITICAL(&s_keys_lock);
portEXIT_CRITICAL();
return 0;
}