0

I'm rewriting existing real-time kernel TNKernel; I have used it for a couple of years, but I don't like many of its design decisions (as well as implementation details), so I decided to fork it and have fun implementing what I want. Anyone who is interested might read additional information at the project page on bitbucket.

TNKernel has one strange, in my opinion, feature: it has service tn_task_sleep(int timeout) which puts current task to sleep, and it has tn_task_wakeup(struct TN_Task *task) which wakes currently sleeping task up.

The strangeness is that it is legal to call tn_task_wakeup() on non-sleeping task; in this case, special flag like wakeup_request will be set, and on the next call to tn_task_sleep() this flag will be cleared, and task won't sleep.

All of this seems to me as a completely dirty hack, it probably might be used as a workaround to avoid race condition problems, or as a hacky replacement for semaphore.

It just encourages programmer to go with hacky approach, instead of creating straightforward semaphore and provide proper synchronization. So, I'm willing to remove this service from my project. Is this good idea to get rid of it, or have I missed something important? Why do we ever need that?

Dmitry Frank
  • 10,417
  • 10
  • 64
  • 114
  • It sounds more like a bug, since the documentation states that tn_task_resume should return an error if the task is not already in the SUSPENDED or WAITING_SUSPENDED state. – nos Sep 15 '14 at 21:53
  • @nos, oh, for some reason I mixed things up in my question, please sorry: of course I've meant `tn_task_wakeup()`, not `tn_task_resume()` (which is related to suspended, not sleeping task). By the way, about `tn_task_wakeup()`: doc states: "*if the task is not in the sleep mode, the wakeup request for the task is queued and the wakeup request counter is incremented by 1*", but if you look in the source, there is intended maximum value of that counter: `1`, so it is essentially a flag. In any case, this seems to me as a dirty hack. – Dmitry Frank Sep 15 '14 at 22:35

1 Answers1

0

Since no one said that I'm wrong, I assumed that I'm right and removed these strange "features" from my kernel.

Dmitry Frank
  • 10,417
  • 10
  • 64
  • 114