How to understand OS_SCHEDULE ?

How to understand OS_SCHEDULE ?

Postby Yevpator » Tue Jun 06, 2017 5:32 am


I have failed to understand the last row in the following macro definition that resides in cocoos.h. To be more specific, I have two questions:
1. What does "case (__LINE__+ofs):" do after return command ?
2. What is the "case" doing here without any "switch "?

#define OS_SCHEDULE(ofs) os_task_internal_state_set(running_tid, __LINE__+ofs);\
running_tid = NO_TID;\
case (__LINE__+ofs):

Thanks in advance!
Posts: 1
Joined: Mon Jun 05, 2017 3:44 pm

Re: How to understand OS_SCHEDULE ?

Postby peter » Mon Aug 07, 2017 3:50 pm

Each task function contains the following code:
Code: Select all
int taskProc() {

The open() and close() calls, are replaced by the preprocessor with the OS_BEGIN and OS_END macros that creates a switch statement.
In between open() and close(), you insert your code and calls to scheduling operations, e.g. event_wait();. These calls contains calls to the OS_SCHEDULE macro.

The OS_SCHEDULE macro sets the internal state of the task to a value equal to the current line number + offset, and creates a case label with that value.
The next time the task is executed, the switch statement is executed and the the task internal state indicates with case to jump to.

So the answers to your questions are:
1. "case (__LINE__+ofs)" creates a case label with the value __LINE__+ofs.
2. The case is inside the switch statement created by task_open() and task_close().

Site Admin
Posts: 24
Joined: Wed Mar 07, 2012 9:32 am

Return to General topics

Who is online

Users browsing this forum: No registered users and 1 guest