Inserting a semaphore into ch_thread
Posted: Fri Jan 12, 2018 12:28 am
Hi,
full-duplex socket operation in LWIP 2.0 requires a dedicated semaphore per thread. I found the CH_CFG_THREAD_EXTRA_FIELDS macro which enables additional fields in the thread structure with CH_CFG_THREAD_INIT_HOOK and CH_CFG_THREAD_EXIT_HOOK to initialize and finalize them. So far so good.
But if I add a struct ch_semaphore as a new field, I get "has incomplete type" compilation errors from all around the OS code, which is understandable.
If I add a struct ch_semaphore*, I need to actually allocate the memory for the semaphore, which can be done with CH_CFG_THREAD_INIT_HOOK but I have no idea how to allocate memory there as chHeapAlloc() cannot be called from a lock zone in which _thread_init (that calls CH_CFG_THREAD_INIT_HOOK) resides. Allocating the memory with chCoreAllocI() seems like a bad idea as it can't be freed.
Any idea what the solution is here? Thanks!
full-duplex socket operation in LWIP 2.0 requires a dedicated semaphore per thread. I found the CH_CFG_THREAD_EXTRA_FIELDS macro which enables additional fields in the thread structure with CH_CFG_THREAD_INIT_HOOK and CH_CFG_THREAD_EXIT_HOOK to initialize and finalize them. So far so good.
But if I add a struct ch_semaphore as a new field, I get "has incomplete type" compilation errors from all around the OS code, which is understandable.
If I add a struct ch_semaphore*, I need to actually allocate the memory for the semaphore, which can be done with CH_CFG_THREAD_INIT_HOOK but I have no idea how to allocate memory there as chHeapAlloc() cannot be called from a lock zone in which _thread_init (that calls CH_CFG_THREAD_INIT_HOOK) resides. Allocating the memory with chCoreAllocI() seems like a bad idea as it can't be freed.
Any idea what the solution is here? Thanks!