I just committed a prototype of this new mechanism "Delegate Threads" in the OSLIB, in brief it is built on top of messages and allows to invoke C functions in the context of another thread.
Imagine encapsulating a whole non-thread-safe subsystem inside a thread, for example a graphic library or a file system. Other threads will be able to call functions of the subsystem from remote without having to implement an ad-hoc messages protocol or implementing mutual exclusion, calls are implicitly synchronized.
The delegate thread has to implement something like this:
Code: Select all
/* Messages dispatcher loop.*/
while (true) {
chDelegateDispatchTimeout(TIME_INFINITE) {
}
Other threads will be able to call functions inside the delegate using:
Code: Select all
ret = chDelegateCallDirect2(tp, remote_func, p1, p2);
It is also possible to hide details by creating convenient proxy functions like this:
Code: Select all
static inline int my_remote_func(int p1, int p2) {
return (int)chDelegateCallDirect2(tp, remote_func, p1, p2):
}
The general idea is to create wrappers for common external subsystems using an unified remote call layer. I am thinking to FatFS and LittlevGL. The mechanism has an overhead of two thread-to-thread context switch operations, which is very efficient in ChibiOS.
Giovanni