On Fri, Jan 29, 2021 at 12:24 AM Sebastian Huber < sebastian.hu...@embedded-brains.de> wrote:
> Do not use an enum as a bit field. Document the state flags. > > This fix relates to a Coverity issue (PW.MIXED_ENUM_TYPE). > --- > cpukit/include/rtems/score/thread.h | 57 ++++++++++++++++++++++++----- > 1 file changed, 47 insertions(+), 10 deletions(-) > > diff --git a/cpukit/include/rtems/score/thread.h > b/cpukit/include/rtems/score/thread.h > index 8785879184..82d98f278a 100644 > --- a/cpukit/include/rtems/score/thread.h > +++ b/cpukit/include/rtems/score/thread.h > @@ -659,22 +659,59 @@ typedef struct { > } Thread_Action_control; > > /** > - * @brief Thread life states. > + * @brief This type represents the thread life state. > * > - * The thread life states are orthogonal to the thread states used for > + * The thread life state are orthogonal to the thread state used for > s/are/is or s/life state/life states > * synchronization primitives and blocking operations. They reflect the > state * changes triggered with thread restart and delete requests. > * > - * The individual state values must be a power of two to allow use of bit > + * The individual state flags must be a power of two to allow use of bit > * operations to manipulate and evaluate the thread life state. > */ > -typedef enum { > - THREAD_LIFE_PROTECTED = 0x1, > - THREAD_LIFE_RESTARTING = 0x2, > - THREAD_LIFE_TERMINATING = 0x4, > - THREAD_LIFE_CHANGE_DEFERRED = 0x8, > - THREAD_LIFE_DETACHED = 0x10 > -} Thread_Life_state; > +typedef int Thread_Life_state; > Maybe unsigned is better? It can be safer sometimes for undefined behaviors. this shouldn't matter greatly. It just doesn't make sense to call a combination of flags as a signed value. > + > +/** > + * @brief Indicates that the thread life is protected. > + * > + * If this flag is set, then the thread restart or delete requests are > deferred > + * until the protection and deferred change flags are cleared. It is > used by > + * _Thread_Set_life_protection(). > + */ > thanks for improving the doxygen along the way. > +#define THREAD_LIFE_PROTECTED 0x1 > + > +/** > + * @brief Indicates that thread is restarting. > + * > + * If this flag is set, then a thread restart request is in pending. See > + * _Thread_Restart_self() and _Thread_Restart_other(). > + */ > +#define THREAD_LIFE_RESTARTING 0x2 > + > +/** > + * @brief Indicates that thread is terminating. > + * > + * If this flag is set, then a thread termination request is in pending. > See > + * _Thread_Exit() and _Thread_Cancel(). > + */ > +#define THREAD_LIFE_TERMINATING 0x4 > + > +/** > + * @brief Indicates that thread life changes are deferred. > + * > + * If this flag is set, then the thread restart or delete requests are > deferred > + * until the protection and deferred change flags are cleared. It is > used by > + * pthread_setcanceltype(). > + */ > +#define THREAD_LIFE_CHANGE_DEFERRED 0x8 > + > +/** > + * @brief Indicates that thread is detached. > + * > + * If this flag is set, then the thread is detached. Detached threads do > not > + * wait during termination for other threads to join. See > rtems_task_delete(), > + * rtems_task_exit(), and pthread_detach(). > + */ > +#define THREAD_LIFE_DETACHED 0x10 > > /** > * @brief Thread life control. > -- > 2.26.2 > > _______________________________________________ > devel mailing list > devel@rtems.org > http://lists.rtems.org/mailman/listinfo/devel >
_______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel