* if timer is pending, mark timer as running */
| 269 | * if timer is pending, mark timer as running |
| 270 | */ |
| 271 | static int |
| 272 | timer_set_running_state(struct rte_timer *tim) |
| 273 | { |
| 274 | union rte_timer_status prev_status, status; |
| 275 | unsigned lcore_id = rte_lcore_id(); |
| 276 | int success = 0; |
| 277 | |
| 278 | /* wait that the timer is in correct status before update, |
| 279 | * and mark it as running */ |
| 280 | prev_status.u32 = rte_atomic_load_explicit(&tim->status.u32, rte_memory_order_relaxed); |
| 281 | |
| 282 | while (success == 0) { |
| 283 | /* timer is not pending anymore */ |
| 284 | if (prev_status.state != RTE_TIMER_PENDING) |
| 285 | return -1; |
| 286 | |
| 287 | /* we know that the timer will be pending at this point |
| 288 | * mark it atomically as being running |
| 289 | */ |
| 290 | status.state = RTE_TIMER_RUNNING; |
| 291 | status.owner = (int16_t)lcore_id; |
| 292 | /* RUNNING states are acting as locked states. If the |
| 293 | * timer is in RUNNING state, the state cannot be changed |
| 294 | * by other threads. So, we should use ACQUIRE here. |
| 295 | */ |
| 296 | success = rte_atomic_compare_exchange_strong_explicit(&tim->status.u32, |
| 297 | (uint32_t *)(uintptr_t)&prev_status.u32, |
| 298 | status.u32, |
| 299 | rte_memory_order_acquire, |
| 300 | rte_memory_order_relaxed); |
| 301 | } |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * Return a skiplist level for a new entry. |
no test coverage detected