I've used that sort of construct in the past and have confirmed that it solves the problem (in addition to producing cleaner-looking code).
Thank you! Bill On Mon, Nov 3, 2014 at 2:45 AM, Shmulik Ladkani <[email protected]> wrote: > Hi Bill, > > On Sun, 2 Nov 2014 21:50:18 -0600 Bill Fischofer < > [email protected]> wrote: > > I'm working on code to implement the new buffer APIs and have the > following > > internal function: > > > > static inline void *get_block(struct pool_entry_s *pool) > > { > > void volatile *oldhead; > > void volatile *newhead; > > > > do { > > oldhead = pool->blk_freelist; > > if (oldhead == NULL) break; > > newhead = ((odp_buf_blk_t *)oldhead)->next; > > } while (odp_cs(pool->blk_freelist,oldhead,newhead) == 0); > > > > return (void *)oldhead; > > } > > > > However when compiling this generates the following strange error > message: > > > > ./include/odp_buffer_pool_internal.h: In function 'get_block': > > ./include/odp_buffer_pool_internal.h:88:14: error: cast discards > > '__attribute__((noreturn))' qualifier from pointer target type > > [-Werror=cast-qual] > > newhead = ((odp_buf_blk_t *)oldhead)->next; > > ^ > > On gcc version 4.9.1 it gives: > > warning: cast discards 'volatile' qualifier from pointer target type > [-Wcast-qual] > newhead = ((odp_buf_blk_t *)oldhead)->next; > ^ > > The warning is indeed correct and suitable for -Wcast-qual, since > 'oldhead' is a volatile pointer while it is casted to a non volatile > pointer type. > > In your gcc the warning output shown is incorrect. > > Using -Wcast-qual is a bit evil. It won't allow you to cast away > properties of pointers such as const or volatile without some tricks. > > The easy option would be to disable -Wcast-qual. > > However this might work for you: > > #define VOLATILE_ACCESS_PTR(p) \ > ((typeof(p))(uintptr_t) *(volatile typeof(p) const *)&(p)) > > static inline void *get_block(struct pool_entry_s *pool) > { > void *oldhead; > void *newhead; > > do { > oldhead = VOLATILE_ACCESS_PTR(pool->blk_freelist); > if (oldhead == NULL) break; > newhead = ((odp_buf_blk_t *)oldhead)->next; > } while (odp_cs(pool->blk_freelist,oldhead,newhead) == 0); > > > return oldhead; > } > > Advantage is pool->blk_freelist is accessed once (which I beleive was > your intention), and encapsulating all details of the ugly casts needed > to solve -Wcast-qual warnings into a single place. > > Regards, > Shmulik >
_______________________________________________ lng-odp mailing list [email protected] http://lists.linaro.org/mailman/listinfo/lng-odp
