RIOT-OS / RIOT

RIOT - The friendly OS for IoT
https://riot-os.org
GNU Lesser General Public License v2.1
4.94k stars 1.99k forks source link

definition of thread flags are uncoordindated between modules #20867

Open Enoch247 opened 1 month ago

Enoch247 commented 1 month ago

Description

There is a macro THREAD_FLAG_PREDEFINED_MASK to capture thread flags in-use by RIOT to allow applications to avoid collisions when using flags. However, many flags are in-use inside of modules and are not captured in this macro. Worse, some flags even within RIOT are defined to the same value. All flag definitions should be moved to thread_flags.h and added to the THREAD_FLAG_PREDEFINED_MASK macro.

Flags to add to THREAD_FLAG_PREDEFINED_MASK (found with git grep THREAD_FLAG | grep "#define"):

Versions

mguetschow commented 1 month ago

Hum, any idea how we could convey the information that a flag is used only if the respective module is actually selected? Otherwise at some point we will end up having most if not all bits already in the predefined mask and the mask won't be useful anymore.

Enoch247 commented 1 month ago

Hum, any idea how we could convey the information that a flag is used only if the respective module is actually selected? Otherwise at some point we will end up having most if not all bits already in the predefined mask and the mask won't be useful anymore.

We could try something like (untested, but seems like it would work):

enum _thread_flag_pos {

#ifdef MODULE_FOO
   _THREAD_FLAG_FOO,
  #define THREAD_FLAG_FOO (1 < _THREAD_FLAG_FOO)
#endif

#ifdef MODULE_BAR
   _THREAD_FLAG_BAR,
  #define THREAD_BAR_FOO (1 < _THREAD_FLAG_BAR)
#endif

    THREAD_FLAG_NUMOF
}
static_assert(THREAD_FLAG_NUMOF < 8);
Enoch247 commented 1 month ago

Adding a link with some valuable comments about this issue from the RIOT chat: https://matrix.to/#/!pqHdpanAvkJvlCwUDE:matrix.org/$HbXRfijYIzubvzvQExivS1bgxEWdGD6lc7nZ67QQLAQ?via=matrix.org&via=tu-dresden.de&via=utwente.io

To summarize the comments from the link; flags don't have to be unique in all cases, but if they are re-used, it should be done so intentionally.

mguetschow commented 1 month ago

We could try something like (untested, but seems like it would work) ...

Neat trick. And to get the predefined flags something like this?

#ifdef MODULE_FOO
   _THREAD_FLAG_FOO,
  #define THREAD_FLAG_FOO (1 < _THREAD_FLAG_FOO)
#else
  #define THREAD_FLAG_FOO (0)
#endif

#define THREAD_FLAG_PREDEFINED_MASK THREAD_FLAG_FOO | THREAD_FLAG_BAR
Enoch247 commented 1 month ago

Neat trick. And to get the predefined flags something like this?

#ifdef MODULE_FOO
   _THREAD_FLAG_FOO,
  #define THREAD_FLAG_FOO (1 < _THREAD_FLAG_FOO)
#else
  #define THREAD_FLAG_FOO (0)
#endif

#define THREAD_FLAG_PREDEFINED_MASK THREAD_FLAG_FOO | THREAD_FLAG_BAR

Yes, I believe that will work.

mguetschow commented 1 month ago

Then in my opinion that would be the way to go for #20868 and similar ones.