jlaitine commented on code in PR #16194: URL: https://github.com/apache/nuttx/pull/16194#discussion_r2041066440
########## include/nuttx/semaphore.h: ########## @@ -45,23 +45,43 @@ /* 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 NXMUTEX_BLOCKS_BIT (((uint32_t)1) << 31) Review Comment: On a second thought, I don't want to do that. Counter value is very different thing than a mutex holder, only thing in common is that they both act as a lock. Counting semaphore value is an integer. Mutex holder, however, is a bitmask, consisting of the "blocking" bit and the TID. And you still modify the holder with bitwise operations, since it is *not* a single integer. Even though what you suggest works, I think it is conceptually wrong, and mixes up computer arithmetics (you change the interpreted value to a negative number by setting the blocking bit manually, instead of doing some real integer operations.). It makes more sense to really keep them separate, counter as an integer and the bitmask as uint32_t. I hope you understand my thinking on this... -- 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