On Mon, 2019-03-11 at 13:52 +0800, Joyce Kong wrote:
> The spinlock implementation is unfair, some threads may take locks
> aggressively while leaving the other threads starving for long time.
> 
> This patch introduces ticketlock which gives each waiting thread a
> ticket and they can take the lock one by one. First come, first
> serviced.
> This avoids starvation for too long time and is more predictable.
> 
> Suggested-by: Jerin Jacob <jer...@marvell.com>
> Signed-off-by: Joyce kong <joyce.k...@arm.com>
> Reviewed-by: Gavin Hu <gavin...@arm.com>
> Reviewed-by: Ola Liljedahl <ola.liljed...@arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagaraha...@arm.com>
> ---
> +static inline __rte_experimental int
> +rte_ticketlock_trylock(rte_ticketlock_t *tl)
> +{
> +     unsigned int next = __atomic_load_n(&tl->next,
> __ATOMIC_RELAXED);
> +     unsigned int cur = __atomic_load_n(&tl->current,
> __ATOMIC_RELAXED);
> +     if (next == cur) {
> +             if (__atomic_compare_exchange_n(&tl->next, &next,
> next+1,
> +                 0, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))

gcc 8.2 emits the following compilation error.

/export/dpdk.org/build/include/generic/rte_ticketlock.h:93:46: error:
incompatible pointer types passing 'unsigned int *' to parameter of
type 'uint16_t *' (aka 'unsigned short *') [-Werror,-Wincompatible-
pointer-types]
                if (__atomic_compare_exchange_n(&tl->next, &next,
next+1,





> +                     return 1;
> +     }
> +
> +     return 0;
> +}
> +
> 

Reply via email to