-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pthread): Add esp_pthread function implementations for linux target (IDFGH-13485) #14384
fix(pthread): Add esp_pthread function implementations for linux target (IDFGH-13485) #14384
Conversation
👋 Hello cristianfunes79, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
Closes #14387 |
Thanks for adding this, we'll take a look! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cristianfunes79 Thanks for this PR, it looks great. I just have one minor comment.
I think this is a good improvement as it keeps the basic behavior of the API on the Linux target aligned with the behavior of the API on the chip targets. This means less surprises for users.
} | ||
*p = *cfg; | ||
p->stack_alloc_caps = heap_caps; | ||
pthread_setspecific(s_pthread_cfg_key, p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really minor thing: I'd suggest to add an assert here to make sure pthread_setspecific()
succeeds, even though the chance is probably very little:
pthread_setspecific(s_pthread_cfg_key, p); | |
int __attribute((unused)) res = pthread_setspecific(s_pthread_cfg_key, p); | |
assert(res == 0); |
You may need to #include assert.h
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I've tried it but it is not so straight forward, as soon as linux doesnt call esp_pthread_init, cfg_key is never created and setspecific assertion fails. I'll take a look on how to resolve that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xjakob Actually I'm thinking about all functions marked as ESP_SYSTEM_INIT_FN
. Does it make sense to create a ticket to implement a way to run such functions in linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried it but it is not so straight forward
Oh, sorry, I didn't think about that. I think you could try to use __attribute__((constructor))
to create a constructor function to initialize the key. __attribute__((constructor))
is documented in the GCC function attributes doc page
ESP_SYSTEM_INIT_FN
won't work on Linux. It's not clear yet, either, if we will implement it on Linux or not. We have a ticket for exactly this in our own ticket system already. Unless you have a concrete reason to implement it, there is no need to create a ticket here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'll add constructor. The reason I can think to add ESP_SYSTEM_INIT_FN
is to have more similar firmware behavior in linux than in xtensa. Maybe it could be as simple as creating a #define ESP_SYSTEM_INIT_FN(foo) __attribute__((constructor)) foo
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xjakob this is ready for review
7dcfd0b
to
92bfb26
Compare
sha=92bfb26639e40149d02140a1f672254c4e161f15 |
@cristianfunes79 We're merging this into our internal repository. Afterwards, it should soon be synchronized to master. |
Thanks for contribution again, changes have been merged with 4c7d9f9. |
This PR is to add functionality to pthread port for linux target. It extends changes done in #14339
DESCRIPTION
As soon as pthread implementation for linux uses libpthread, it is not possible to use esp custom functions for setting pthread parameters.
But this implementation at least can be use to validate arguments passed to the functions.
DETAILED DESCRIPTION
When using pthread_create esp implementation, it uses freeRTOS task behind to create a new execution thread. This implementation uses
pthread_getspecifics
to get values set byesp_pthread_set_cfg (const esp_pthread_cfg_t *cfg)
(see https://github.com/espressif/esp-idf/blob/master/components/pthread/pthread.c#L309).When using linux target, that custom pthread implementation is no more used, so all
esp_pthread.h
functions doesn't affect thread creation.