diff mbox

[3/3] linux-generic: timer: remove atomic ifdef from timer_reset() function body

Message ID 1426076147-10053-4-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov March 11, 2015, 12:15 p.m. UTC
No functional changes, just make code more readable.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/odp_timer.c | 76 +++++++++++++++++++++++++++-----------
 1 file changed, 54 insertions(+), 22 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
index 33c2758..36480ed 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -334,6 +334,7 @@  static inline odp_buffer_t timer_free(odp_timer_pool *tp, uint32_t idx)
  * expire/reset/cancel timer
  *****************************************************************************/
 
+#ifdef ODP_ATOMIC_U128
 static bool timer_reset(uint32_t idx,
 		uint64_t abs_tck,
 		odp_buffer_t *tmo_buf,
@@ -343,8 +344,8 @@  static bool timer_reset(uint32_t idx,
 	tick_buf_t *tb = &tp->tick_buf[idx];
 
 	if (tmo_buf == NULL || *tmo_buf == ODP_BUFFER_INVALID) {
-#ifdef ODP_ATOMIC_U128
 		tick_buf_t new, old;
+
 		do {
 			/* Relaxed and non-atomic read of current values */
 			old.exp_tck.v = tb->exp_tck.v;
@@ -370,11 +371,52 @@  static bool timer_reset(uint32_t idx,
 					(_uint128_t *)&new,
 					_ODP_MEMMODEL_RLS,
 					_ODP_MEMMODEL_RLX));
-#else
+	} else {
+		/* We have a new timeout buffer which replaces any old one */
+		/* Fill in header fields if timeout event */
+		if (_odp_buffer_type(*tmo_buf) == ODP_EVENT_TIMEOUT) {
+			/* Convert from buffer to timeout hdr */
+			odp_timeout_hdr_t *tmo_hdr =
+				timeout_hdr_from_buf(*tmo_buf);
+			tmo_hdr->timer = tp_idx_to_handle(tp, idx);
+			tmo_hdr->user_ptr = tp->timers[idx].user_ptr;
+			/* expiration field filled in when timer expires */
+		}
+		/* Else ignore buffers of other types */
+		odp_buffer_t old_buf = ODP_BUFFER_INVALID;
+		tick_buf_t new, old;
+		new.exp_tck.v = abs_tck;
+		new.tmo_buf = *tmo_buf;
+		TB_SET_PAD(new);
+		/* We are releasing the new timeout buffer to some other
+		 * thread */
+		_odp_atomic_u128_xchg_mm((_odp_atomic_u128_t *)tb,
+					 (_uint128_t *)&new,
+					 (_uint128_t *)&old,
+					 _ODP_MEMMODEL_ACQ_RLS);
+		old_buf = old.tmo_buf;
+		/* Return old timeout buffer */
+		*tmo_buf = old_buf;
+	}
+	return success;
+}
+
+#else /*ODP_ATOMIC_U128*/
+
+static bool timer_reset(uint32_t idx,
+		uint64_t abs_tck,
+		odp_buffer_t *tmo_buf,
+		odp_timer_pool *tp)
+{
+	bool success = true;
+	tick_buf_t *tb = &tp->tick_buf[idx];
+
+	if (tmo_buf == NULL || *tmo_buf == ODP_BUFFER_INVALID) {
 #ifdef __ARM_ARCH
 		/* Since barriers are not good for C-A15, we take an
 		 * alternative approach using relaxed memory model */
 		uint64_t old;
+
 		/* Swap in new expiration tick, get back old tick which
 		 * will indicate active/inactive timer state */
 		old = _odp_atomic_u64_xchg_mm(&tb->exp_tck, abs_tck,
@@ -398,7 +440,7 @@  static bool timer_reset(uint32_t idx,
 					_ODP_MEMMODEL_RLX);
 			success = false;
 		}
-#else
+#else /*__ARM_ARCH*/
 		/* Take a related lock */
 		while (_odp_atomic_flag_tas(IDX2LOCK(idx)))
 			/* While lock is taken, spin using relaxed loads */
@@ -417,9 +459,10 @@  static bool timer_reset(uint32_t idx,
 
 		/* Release the lock */
 		_odp_atomic_flag_clear(IDX2LOCK(idx));
-#endif
-#endif
+#endif /*__ARM_ARCH*/
 	} else {
+		odp_buffer_t old_buf;
+
 		/* We have a new timeout buffer which replaces any old one */
 		/* Fill in header fields if timeout event */
 		if (_odp_buffer_type(*tmo_buf) == ODP_EVENT_TIMEOUT) {
@@ -429,22 +472,10 @@  static bool timer_reset(uint32_t idx,
 			tmo_hdr->timer = tp_idx_to_handle(tp, idx);
 			tmo_hdr->user_ptr = tp->timers[idx].user_ptr;
 			/* expiration field filled in when timer expires */
+		} else {
+			/* Else ignore buffers of other types */
 		}
-		/* Else ignore buffers of other types */
-		odp_buffer_t old_buf = ODP_BUFFER_INVALID;
-#ifdef ODP_ATOMIC_U128
-		tick_buf_t new, old;
-		new.exp_tck.v = abs_tck;
-		new.tmo_buf = *tmo_buf;
-		TB_SET_PAD(new);
-		/* We are releasing the new timeout buffer to some other
-		 * thread */
-		_odp_atomic_u128_xchg_mm((_odp_atomic_u128_t *)tb,
-					 (_uint128_t *)&new,
-					 (_uint128_t *)&old,
-					 _ODP_MEMMODEL_ACQ_RLS);
-		old_buf = old.tmo_buf;
-#else
+
 		/* Take a related lock */
 		while (_odp_atomic_flag_tas(IDX2LOCK(idx)))
 			/* While lock is taken, spin using relaxed loads */
@@ -460,13 +491,14 @@  static bool timer_reset(uint32_t idx,
 
 		/* Release the lock */
 		_odp_atomic_flag_clear(IDX2LOCK(idx));
-#endif
+
 		/* Return old timeout buffer */
 		*tmo_buf = old_buf;
 	}
+
 	return success;
 }
-
+#endif /*ODP_ATOMIC_U128*/
 
 #ifdef ODP_ATOMIC_U128
 static odp_buffer_t timer_cancel(odp_timer_pool *tp,