Task::delay is not public #2
Replies: 8 comments 2 replies
-
|
I think the original idea here was to try and enforce the idea that any call to This helps prevent someone from calling Another way to look at this is that Here By this same logic |
Beta Was this translation helpful? Give feedback.
-
|
I understand. Indeed, delaying another task is confusing. What about a different approach: create a new class this_task, like so: That way, the api makes it clearer thay you are delaying the current task, and there is no relation with a specific task. (admitted: this is inspired by https://github.com/IntergatedCircuits/freertos-mcpp/blob/master/include/freertos/thread.h#L443) |
Beta Was this translation helpful? Give feedback.
-
|
That is similar to what I do for other functions that are part of the This is a new library, so I'm not sure how people will use it yet. Are you wanting to use this functionality in many classes or just this one? Would it makes sense to declare your class a friend of your task class? |
Beta Was this translation helpful? Give feedback.
-
|
I am using the delay in a device driver that is to be used by multiple applications. So making that class a friend won't work, as the class is in a separate library. Moving delay to FreeRTOS::Kernel would work. I am not sure on how nice that solution is. But I also just starting using your library, so I am still looking for the best way to use it. |
Beta Was this translation helpful? Give feedback.
-
|
My initial thought/question would be why does your device driver need to delay the task? If someone else were to use the class would it unexpectedly be delaying the thread? A high-level guideline I would give for the library would be only delay the task from the task class (which is why it's protected). Construct the driver interface in way that doesn't "hide" thread delays from the application. If that doesn't work, I'd suggest making your driver it's own |
Beta Was this translation helpful? Give feedback.
-
|
I'm writing a library for my own use, not a public library. For me, the design of drivers or other library classes delaying the task work. I just make sure to document it. My MCU doesn't have enough memory to have many tasks. I can always add my own 'ThisTask' class ofcourse, if that doesn't fit in your design. |
Beta Was this translation helpful? Give feedback.
-
|
I would say do that for now. If it's just a static method I would throw it in a namespace. Something like: The design is intended to stop you from doing exactly what you're trying to do, so I don't want to change it yet. If others also find this too restrictive then I'll consider changing it in the future. |
Beta Was this translation helpful? Give feedback.
-
|
@jonenz @electretmike , hey guys, I find this topic relevant and really important. I want to share my take. I think it is good to imply good usage pattern but it should not be forced. Why should a FreeRTOS C++ wrapper restrict me from using FreeRTOS the way it can be used with the original C API? I think this is outside wrapper's responsibility to do so, otherwise it is more than just a wrapper. I think it is a design choice of the FreeRTOS itself that delay does not require a task handle and it implies a delay for the current task. Anyone who uses FreeRTOS already knows it. I think making Moreover - why can't I use Also, if impact and reach of this project is of any concern, I think that restrictiveness of methods like However, don't get me wrong, @jonenz idea to make a safer FreeRTOS API is interesting. Maybe it should be a separate optional layer that goes on top of a basic wrapper? Just an idea. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a class that inherits from Task. This works very well. Thank you for these nice wrappers! Except that this class calls methods in other classes, which need to delay the current task. Those classes don't have access to Task::delay, because it is protected. For me, it would help if it was public.
Is there any objection against that?
Beta Was this translation helpful? Give feedback.
All reactions