src/dpdk/lib/librte_timer/rte_timer.c
static int
timer_set_config_state(struct rte_timer *tim,
		       union rte_timer_status *ret_prev_status,
		       struct priv_timer *priv_timer)
{
	union rte_timer_status prev_status, status;
	int success = 0;
	unsigned lcore_id;

	lcore_id = rte_lcore_id();

	/* wait that the timer is in correct status before update,
	 * and mark it as being configured */
	prev_status.u32 = __atomic_load_n(&tim->status.u32, __ATOMIC_RELAXED);

	while (success == 0) {
		/* timer is running on another core
		 * or ready to run on local core, exit
		 */
		if (prev_status.state == RTE_TIMER_RUNNING &&
		    (prev_status.owner != (uint16_t)lcore_id ||
		     tim != priv_timer[lcore_id].running_tim))
			return -1;

		/* timer is being configured on another core */
		if (prev_status.state == RTE_TIMER_CONFIG)
			return -1;

		/* here, we know that timer is stopped or pending,
		 * mark it atomically as being configured */
		status.state = RTE_TIMER_CONFIG;
		status.owner = (int16_t)lcore_id;
		/* CONFIG states are acting as locked states. If the
		 * timer is in CONFIG state, the state cannot be changed
		 * by other threads. So, we should use ACQUIRE here.
		 */
		success = __atomic_compare_exchange_n(&tim->status.u32,
					      &prev_status.u32,
					      status.u32, 0,
					      __ATOMIC_ACQUIRE,
					      __ATOMIC_RELAXED);
	}

	ret_prev_status->u32 = prev_status.u32;
	return 0;
}
/*
 * if timer is pending or stopped (or running on the same core than
 * us), mark timer as configuring, and on success return the previous
 * status of the timer
 */
if timer is pending or stopped (or running on the same core than
us), mark timer as configuring, and on success return the previous
status of the timer
if timer is pending or stopped ( or running on the same core than us ) mark timer as configuring and on success return the previous status of the timer
static int
timer_set_config_state(struct rte_timer *tim,
		       union rte_timer_status *ret_prev_status,
		       struct priv_timer *priv_timer)
{
	union rte_timer_status prev_status, status;
	int success = 0;
	unsigned lcore_id;
	lcore_id = rte_lcore_id();
	prev_status.u32 = __atomic_load_n(&tim->status.u32, __ATOMIC_RELAXED);
	while (success == 0) {
		if (prev_status.state == RTE_TIMER_RUNNING &&
		    (prev_status.owner != (uint16_t)lcore_id ||
		     tim != priv_timer[lcore_id].running_tim))
			return -1;
		if (prev_status.state == RTE_TIMER_CONFIG)
			return -1;
		status.state = RTE_TIMER_CONFIG;
		status.owner = (int16_t)lcore_id;
		success = __atomic_compare_exchange_n(&tim->status.u32,
					      &prev_status.u32,
					      status.u32, 0,
					      __ATOMIC_ACQUIRE,
					      __ATOMIC_RELAXED);
	}
	ret_prev_status->u32 = prev_status.u32;
	return 0;
}
static int timer_set_config_state ( struct rte_timer * tim , union rte_timer_status * ret_prev_status , struct priv_timer * priv_timer ) { union rte_timer_status prev_status , status ; int success = 0 ; unsigned lcore_id ; lcore_id = rte_lcore_id ( ) ; prev_status . u32 = __atomic_load_n ( & tim -> status . u32 , __ATOMIC_RELAXED ) ; while ( success == 0 ) { if ( prev_status . state == RTE_TIMER_RUNNING && ( prev_status . owner != ( uint16_t ) lcore_id || tim != priv_timer [ lcore_id ] . running_tim ) ) return -1 ; if ( prev_status . state == RTE_TIMER_CONFIG ) return -1 ; status . state = RTE_TIMER_CONFIG ; status . owner = ( int16_t ) lcore_id ; success = __atomic_compare_exchange_n ( & tim -> status . u32 , & prev_status . u32 , status . u32 , 0 , __ATOMIC_ACQUIRE , __ATOMIC_RELAXED ) ; } ret_prev_status -> u32 = prev_status . u32 ; return 0 ; }
if timer is pending or stopped (or running on the same core than
 us), mark timer as configuring, and on success return the previous
 status of the timer
if timer is pending or stopped ( or running on the same core than us ) mark timer as configuring and on success return the previous status of the timer
/* wait that the timer is in correct status before update,
	 * and mark it as being configured */ /* timer is running on another core
		 * or ready to run on local core, exit
		 */ /* timer is being configured on another core */ /* here, we know that timer is stopped or pending,
		 * mark it atomically as being configured */ /* CONFIG states are acting as locked states. If the
		 * timer is in CONFIG state, the state cannot be changed
		 * by other threads. So, we should use ACQUIRE here.
		 */