Recursive mutex / newlib retarget lock support #276

Closed
opened 2021-03-14 01:44:48 -06:00 by Wiz-IO · 12 comments
Wiz-IO commented 2021-03-14 01:44:48 -06:00 (Migrated from github.com)

Please add support for recursive mutex
mutex_enter_blocking_recursive()
mutex_try_enter_recursive()
mutex_exit_recursive()

Please add support for **recursive mutex** mutex_enter_blocking_recursive() mutex_try_enter_recursive() mutex_exit_recursive()
lurch commented 2021-03-14 07:07:11 -05:00 (Migrated from github.com)

ping @kilograham

ping @kilograham
Wiz-IO commented 2021-03-19 01:01:38 -05:00 (Migrated from github.com)
just for info ... look this https://github.com/Wiz-IO/LIB/blob/master/pico/pico_mutex/mutex.c#L82 new is only one counter in **mutex_t** https://github.com/Wiz-IO/LIB/blob/master/pico/pico_mutex/mutex.h#L35 results with <sys/lock.h> [no locks](https://raw.githubusercontent.com/Wiz-IO/LIB/master/pico/no-lock.jpg) [with locks](https://raw.githubusercontent.com/Wiz-IO/LIB/master/pico/lock.jpg)
kilograham commented 2021-03-19 07:58:11 -05:00 (Migrated from github.com)

results with <sys/lock.h>
no locks
with locks

Not 100% sure what you are trying to indicate here... I know what a mutex does :-) ... FYI printf in the SDK is already mutex-ed for you by default.

> results with <sys/lock.h> > no locks > with locks Not 100% sure what you are trying to indicate here... I know what a mutex does :-) ... FYI printf in the SDK is already mutex-ed for you by default.
Wiz-IO commented 2021-03-19 08:16:48 -05:00 (Migrated from github.com)

recursive mutex is used for "future" ..... <sys/lock.h> as baremetal and/or FreeRTOS to protect the stdio and file system

recursive mutex is used for "future" ..... <sys/lock.h> as baremetal and/or FreeRTOS to protect the stdio and file system
Wiz-IO commented 2021-03-19 08:23:37 -05:00 (Migrated from github.com)

example: unistd and FILE in Arduino (C++)
RAM Disk + FLASH Disk + SD Card
posix? :) ... need only 5 functions for pthread...
unistd

example: **unistd** and **FILE** in **Arduino (C++)** RAM Disk + FLASH Disk + SD Card posix? :) ... need only 5 functions for pthread... ![unistd](https://user-images.githubusercontent.com/14574834/111786956-0f360500-88c7-11eb-8b13-818914a66bf3.jpg)
kilograham commented 2021-03-24 09:38:32 -05:00 (Migrated from github.com)

So the existing mutex classes should not be used in a FreeRTOS as they are core not task focused (unless you specifically mean core).

Equally, should a recursive mutex be successfully claimed by both application and IRQ on the same core?

So the existing mutex classes should not be used in a FreeRTOS as they are core not task focused (unless you specifically mean core). Equally, should a recursive mutex be successfully claimed by both application and IRQ on the same core?
Wiz-IO commented 2021-03-24 09:51:48 -05:00 (Migrated from github.com)
https://github.com/Wiz-IO/framework-wizio-pico/blob/main/wizio/newlib/lock.c
kilograham commented 2021-03-24 19:07:04 -05:00 (Migrated from github.com)

showing me that code doesn't really answer my question, though I am able to glean that you seem to want the recursive mutexes to work the way that makes them suitable for using in newlib locking (which isn't documented there). (edit i mean you showed me locks that are re-entrant on the same core, I still don't know if this is desirable behavior though for an IRQ to be able to take a lock owned by the application code).

Can you point me at some docs for the newlib locking - since you seem to be implementing the locks defined somewhere, because fixing enabling newlib re-entrancy/locking when using multicore via the raw SDK is likely a good thing anyway (note I was assuming the newlib that comes with gcc just didn't support it, but I guess I am wrong).

showing me that code doesn't really answer my question, though I am able to glean that you seem to want the recursive mutexes to work the way that makes them suitable for using in newlib locking (which isn't documented there). (edit i mean you showed me locks that are re-entrant on the same core, I still don't know if this is desirable behavior though for an IRQ to be able to take a lock owned by the application code). Can you point me at some docs for the newlib locking - since you seem to be implementing the locks defined somewhere, because fixing enabling newlib re-entrancy/locking when using multicore via the raw SDK is likely a good thing anyway (note I was assuming the newlib that comes with gcc just didn't support it, but I guess I am wrong).
Wiz-IO commented 2021-03-25 00:50:14 -05:00 (Migrated from github.com)

I was looking for documents for newlib
found only this...
https://www.cs.ccu.edu.tw/~pahsiung/courses/ese/resources/newlib.pdf

and I applied this in reverse
https://gist.github.com/thomask77/65591d78070ace68885d3fd05cdebe3a

here is my version (as idea)
is only one counter in mutex_t and this
https://github.com/Wiz-IO/framework-wizio-pico/blob/main/SDK/pico/pico_sync/mutex.c#L82

I was looking for documents for newlib found only this... https://www.cs.ccu.edu.tw/~pahsiung/courses/ese/resources/newlib.pdf and I applied this in reverse https://gist.github.com/thomask77/65591d78070ace68885d3fd05cdebe3a here is my version (as idea) is only one counter in mutex_t and this https://github.com/Wiz-IO/framework-wizio-pico/blob/main/SDK/pico/pico_sync/mutex.c#L82
kilograham commented 2021-05-04 14:23:26 -05:00 (Migrated from github.com)

Note recursive mutexes will be added by #378

Note recursive mutexes will be added by #378
lurch commented 2021-05-06 07:08:52 -05:00 (Migrated from github.com)

...have been added... 🙂 (i.e. this can be closed?)

...**have** been added... :slightly_smiling_face: (i.e. this can be closed?)
Wiz-IO commented 2021-05-06 07:13:08 -05:00 (Migrated from github.com)

yep close
this days will test...

yep close this days will test...
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#276
No description provided.