1212 * @brief Flagged single-linked list implementation.
1313 *
1414 * Similar to @ref single-linked-list_apis with the added ability to define
15- * two bits of user "flags" for each node. They can be accessed and modified
15+ * user "flags" bits for each node. They can be accessed and modified
1616 * using the sys_sfnode_flags_get() and sys_sfnode_flags_set() APIs.
1717 *
1818 * Flagged single-linked list implementation using inline macros/functions.
@@ -213,7 +213,10 @@ static inline void sys_sflist_init(sys_sflist_t *list)
213213 */
214214#define SYS_SFLIST_STATIC_INIT (ptr_to_list ) {NULL, NULL}
215215
216- #define SYS_SFLIST_FLAGS_MASK ((uintptr_t)0x3)
216+ /* Flag bits are stored in unused LSB of the sys_sfnode_t pointer */
217+ #define SYS_SFLIST_FLAGS_MASK ((uintptr_t)(__alignof__(sys_sfnode_t) - 1))
218+ /* At least 2 available flag bits are expected */
219+ BUILD_ASSERT (SYS_SFLIST_FLAGS_MASK >= 0x3 );
217220
218221static inline sys_sfnode_t * z_sfnode_next_peek (sys_sfnode_t * node )
219222{
@@ -272,7 +275,8 @@ static inline sys_sfnode_t *sys_sflist_peek_tail(sys_sflist_t *list)
272275 * @brief Fetch flags value for a particular sfnode
273276 *
274277 * @param node A pointer to the node to fetch flags from
275- * @return The value of flags, which will be between 0 and 3
278+ * @return The value of flags, which will be between 0 and 3 on 32-bit
279+ * architectures, or between 0 and 7 on 64-bit architectures
276280 */
277281static inline uint8_t sys_sfnode_flags_get (sys_sfnode_t * node )
278282{
@@ -283,14 +287,15 @@ static inline uint8_t sys_sfnode_flags_get(sys_sfnode_t *node)
283287 * @brief Initialize an sflist node
284288 *
285289 * Set an initial flags value for this slist node, which can be a value between
286- * 0 and 3. These flags will persist even if the node is moved around
287- * within a list, removed, or transplanted to a different slist.
290+ * 0 and 3 on 32-bit architectures, or between 0 and 7 on 64-bit architectures.
291+ * These flags will persist even if the node is moved around within a list,
292+ * removed, or transplanted to a different slist.
288293 *
289294 * This is ever so slightly faster than sys_sfnode_flags_set() and should
290295 * only be used on a node that hasn't been added to any list.
291296 *
292297 * @param node A pointer to the node to set the flags on
293- * @param flags A value between 0 and 3 to set the flags value
298+ * @param flags The flags value to set
294299 */
295300static inline void sys_sfnode_init (sys_sfnode_t * node , uint8_t flags )
296301{
@@ -302,11 +307,12 @@ static inline void sys_sfnode_init(sys_sfnode_t *node, uint8_t flags)
302307 * @brief Set flags value for an sflist node
303308 *
304309 * Set a flags value for this slist node, which can be a value between
305- * 0 and 3. These flags will persist even if the node is moved around
306- * within a list, removed, or transplanted to a different slist.
310+ * 0 and 3 on 32-bit architectures, or between 0 and 7 on 64-bit architectures.
311+ * These flags will persist even if the node is moved around within a list,
312+ * removed, or transplanted to a different slist.
307313 *
308314 * @param node A pointer to the node to set the flags on
309- * @param flags A value between 0 and 3 to set the flags value
315+ * @param flags The flags value to set
310316 */
311317static inline void sys_sfnode_flags_set (sys_sfnode_t * node , uint8_t flags )
312318{
0 commit comments