* Take the pflock for write. * * @param pf * A pointer to the pflock structure. */
| 136 | * A pointer to the pflock structure. |
| 137 | */ |
| 138 | static inline void |
| 139 | rte_pflock_write_lock(rte_pflock_t *pf) |
| 140 | { |
| 141 | uint16_t ticket, w; |
| 142 | |
| 143 | /* Acquire ownership of write-phase. |
| 144 | * This is same as rte_ticketlock_lock(). |
| 145 | */ |
| 146 | ticket = rte_atomic_fetch_add_explicit(&pf->wr.in, 1, rte_memory_order_relaxed); |
| 147 | rte_wait_until_equal_16((uint16_t *)(uintptr_t)&pf->wr.out, ticket, |
| 148 | rte_memory_order_acquire); |
| 149 | |
| 150 | /* |
| 151 | * Acquire ticket on read-side in order to allow them |
| 152 | * to flush. Indicates to any incoming reader that a |
| 153 | * write-phase is pending. |
| 154 | * |
| 155 | * The load of rd.out in wait loop could be executed |
| 156 | * speculatively. |
| 157 | */ |
| 158 | w = RTE_PFLOCK_PRES | (ticket & RTE_PFLOCK_PHID); |
| 159 | ticket = rte_atomic_fetch_add_explicit(&pf->rd.in, w, rte_memory_order_relaxed); |
| 160 | |
| 161 | /* Wait for any pending readers to flush. */ |
| 162 | rte_wait_until_equal_16((uint16_t *)(uintptr_t)&pf->rd.out, ticket, |
| 163 | rte_memory_order_acquire); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Release a pflock held for writing. |