pthread: Allow configuration of priority and stacksize

The expected usage is:
  esp_pthread_set_cfg(cfg);
  pthread_create()

If the inherit flag is set, then all subsequent threads forked by this
thread will also inherit this configuration. This avoids having to
change/prefix this for each and every pthread_create() call.
This commit is contained in:
Kedar Sovani
2018-02-25 14:56:04 +05:30
parent 7594127ca3
commit 7a0cab0a5b
7 changed files with 185 additions and 4 deletions

View File

@@ -0,0 +1,65 @@
ESP-pthread
===========
Overview
--------
This module offers Espressif specific extensions to the pthread library that can be used to influence the behaviour of pthreads. Currently the following configuration can be tuned:
* Stack size of the pthreads
* Priority of the created pthreads
* Inheriting this configuration across threads
Example to tune the stack size of the pthread:
.. highlight:: c
::
main()
{
pthread_t t1;
esp_pthread_cfg_t cfg;
cfg.stack_size = (4 * 1024);
esp_pthread_set_cfg(&cfg);
pthread_create(&t1, NULL, thread_func);
}
The API can also be used for inheriting the settings across threads. For example:
.. highlight:: c
::
void * my_thread2(void * p)
{
/* This thread will inherit the stack size of 4K */
printf("In my_thread2\n");
}
void * my_thread1(void * p)
{
printf("In my_thread1\n");
pthread_t t2;
pthread_create(&t2, NULL, my_thread2);
}
main()
{
pthread_t t1;
esp_pthread_cfg_t cfg;
cfg.stack_size = (4 * 1024);
cfg.inherit_cfg = true;
esp_pthread_set_cfg(&cfg);
pthread_create(&t1, NULL, my_thread1);
}
API Reference
-------------
.. include:: /_build/inc/esp_pthread.inc

View File

@@ -18,6 +18,7 @@ System API
Sleep Modes <sleep_modes>
Base MAC address <base_mac_address>
Over The Air Updates (OTA) <ota>
ESP pthread <esp_pthread>
Example code for this API section is provided in :example:`system` directory of ESP-IDF examples.