jlaitine commented on code in PR #16194: URL: https://github.com/apache/nuttx/pull/16194#discussion_r2063564754
########## include/nuttx/semaphore.h: ########## @@ -45,23 +45,42 @@ /* semcount, flags, waitlist, hhead */ # define NXSEM_INITIALIZER(c, f) \ - {(c), (f), SEM_WAITLIST_INITIALIZER, NULL} + {{(c)}, (f), SEM_WAITLIST_INITIALIZER, NULL} # else /* semcount, flags, waitlist, holder[2] */ # define NXSEM_INITIALIZER(c, f) \ - {(c), (f), SEM_WAITLIST_INITIALIZER, SEMHOLDER_INITIALIZER} + {{(c)}, (f), SEM_WAITLIST_INITIALIZER, SEMHOLDER_INITIALIZER} # endif #else /* CONFIG_PRIORITY_INHERITANCE */ /* semcount, flags, waitlist */ # define NXSEM_INITIALIZER(c, f) \ - {(c), (f), SEM_WAITLIST_INITIALIZER} + {{(c)}, (f), SEM_WAITLIST_INITIALIZER} #endif /* CONFIG_PRIORITY_INHERITANCE */ -/* Macro to retrieve sem count */ +/* Macros to retrieve sem count and to check if nxsem is mutex */ -#define NXSEM_COUNT(s) ((FAR atomic_t *)&(s)->semcount) +#define NXSEM_COUNT(s) ((FAR atomic_t *)&(s)->val.semcount) +#define NXSEM_IS_MUTEX(s) (((s)->flags & SEM_TYPE_MUTEX) != 0) + +/* Mutex related helper macros */ + +#define NXSEM_MBLOCKS_BIT (((uint32_t)1) << 31) +#define NXSEM_NO_MHOLDER ((uint32_t)0x7ffffffe) +#define NXSEM_MRESET ((uint32_t)0x7fffffff) + +/* Macro to retrieve mutex's atomic holder's ptr */ + +#define NXSEM_MHOLDER(s) ((FAR atomic_t *)&(s)->val.mholder) + +/* Check if holder value (TID) is not NO_HOLDER or RESET */ + +#define NXSEM_MACQUIRED(h) (!(((h) & NXSEM_NO_MHOLDER) == NXSEM_NO_MHOLDER)) + +/* Check if mutex is acquired and blocks some other task */ + +#define NXSEM_MBLOCKS(h) (((h) & NXSEM_MBLOCKS_BIT) != 0) Review Comment: I guess I would just use NXSEM_MBLOCKING, NXSEM_MBLOCKING_BIT, NXSEM_MRESET etc. to be consistent and keep the word "Mutex" somehow in the game... -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org