* Try to take the lock. * * @param tl * A pointer to the ticketlock. * @return * 1 if the lock is successfully taken; 0 otherwise. */
| 90 | * 1 if the lock is successfully taken; 0 otherwise. |
| 91 | */ |
| 92 | static inline int |
| 93 | rte_ticketlock_trylock(rte_ticketlock_t *tl) |
| 94 | { |
| 95 | rte_ticketlock_t oldl, newl; |
| 96 | oldl.tickets = rte_atomic_load_explicit(&tl->tickets, rte_memory_order_relaxed); |
| 97 | newl.tickets = oldl.tickets; |
| 98 | newl.s.next++; |
| 99 | if (oldl.s.next == oldl.s.current) { |
| 100 | if (rte_atomic_compare_exchange_strong_explicit(&tl->tickets, |
| 101 | (uint32_t *)(uintptr_t)&oldl.tickets, newl.tickets, |
| 102 | rte_memory_order_acquire, rte_memory_order_relaxed)) |
| 103 | return 1; |
| 104 | } |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Test if the lock is taken. |
no outgoing calls