MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rte_ticketlock_trylock

Function rte_ticketlock_trylock

dpdk/lib/eal/include/rte_ticketlock.h:92–107  ·  view source on GitHub ↗

* Try to take the lock. * * @param tl * A pointer to the ticketlock. * @return * 1 if the lock is successfully taken; 0 otherwise. */

Source from the content-addressed store, hash-verified

90 * 1 if the lock is successfully taken; 0 otherwise.
91 */
92static inline int
93rte_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.

Callers 3

test_ticketlock_tryFunction · 0.85
test_ticketlockFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_ticketlock_tryFunction · 0.68
test_ticketlockFunction · 0.68