This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: What are the __retarget_lock functions?


Hi!

On 10.09.2018 10:53, Freddie Chopin wrote:
> On Sun, 2018-09-09 at 10:59 +0200, Thomas Kindler wrote:
>> 6. __retarget_lock_init() looks too complicated with the double
>> pvPortMalloc/xSemaphoreCreate
>
> That's because the allocation step is useless. FreeRTOS handle is just
> `void*`, you don't need to allocate that, just use `_LOCK_T*` directly.
> FreeRTOS objects (with the standard API) are all dynamic anyway
> (another very stupid decision).
>

Unfortunateley, I found no way to get rid of the additional malloc().

Here it is again (slightly updated):

  https://gist.github.com/thomask77/3a2d54a482c294beec5d87730e163bdd

After fiddling around for a long time, I believe, there is no other way to make it work with FreeRTOS' dynamic allocation.

The problem is, that newlib uses _LOCK_T in __retarget_lock_acquire with the *address* of __lock___malloc_recursive_mutex. For it to work with dynamic allocation, it would have to use the *value* of __lock___malloc_recursive_mutex.

So when implementing __retarget_lock_init, an intermediate pointer is needed (or all of the other functions would need to differentiate between the static __locks and the runtime allocated ones).

But maybe I overlooked something?


The alternative is to use the static FreeRTOS APIs:

  https://gist.github.com/thomask77/65591d78070ace68885d3fd05cdebe3a

this feels much more natural, and matches the newlib conventions.

The drawback is that it pulls in a lot of additional FreeRTOS functions that I don't need anywhere else.

best regards,
Thomas


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]