@@ -62,8 +62,8 @@ static const char *timerset2str(odp_timer_set_t val)
return "too early";
case ODP_TIMER_TOOLATE:
return "too late";
- case ODP_TIMER_NOBUF:
- return "no buffer";
+ case ODP_TIMER_NOEVENT:
+ return "no event";
default:
return "?";
}
@@ -72,7 +72,7 @@ static const char *timerset2str(odp_timer_set_t val)
/** @private Helper struct for timers */
struct test_timer {
odp_timer_t tim;
- odp_buffer_t buf;
+ odp_event_t ev;
};
/** @private Array of all timer helper structs */
@@ -86,6 +86,7 @@ static void test_abs_timeouts(int thr, test_args_t *args)
odp_queue_t queue;
uint64_t tick;
struct test_timer *ttp;
+ odp_buffer_t buf;
EXAMPLE_DBG(" [%i] test_timeouts\n", thr);
@@ -106,11 +107,12 @@ static void test_abs_timeouts(int thr, test_args_t *args)
EXAMPLE_ERR("Failed to allocate timer\n");
return;
}
- ttp->buf = odp_buffer_alloc(pool);
- if (ttp->buf == ODP_BUFFER_INVALID) {
+ buf = odp_buffer_alloc(pool);
+ if (buf == ODP_BUFFER_INVALID) {
EXAMPLE_ERR("Failed to allocate buffer\n");
return;
}
+ ttp->ev = odp_buffer_to_event(buf);
tick = odp_timer_current_tick(tp);
while ((int)odp_atomic_load_u32(&remain) > 0) {
@@ -118,7 +120,7 @@ static void test_abs_timeouts(int thr, test_args_t *args)
odp_timer_set_t rc;
tick += period;
- rc = odp_timer_set_abs(ttp->tim, tick, &ttp->buf);
+ rc = odp_timer_set_abs(ttp->tim, tick, &ttp->ev);
if (odp_unlikely(rc != ODP_TIMER_SUCCESS)) {
/* Too early or too late timeout requested */
EXAMPLE_ABORT("odp_timer_set_abs() failed: %s\n",
@@ -134,14 +136,14 @@ static void test_abs_timeouts(int thr, test_args_t *args)
if (ev == ODP_EVENT_INVALID)
continue; /* Re-check the remain counter */
if (odp_event_type(ev) != ODP_EVENT_TIMEOUT) {
- /* Not a default timeout buffer */
+ /* Not a default timeout event */
EXAMPLE_ABORT("Unexpected event type (%u) received\n",
odp_event_type(ev));
}
odp_timeout_t tmo = odp_timeout_from_event(ev);
tick = odp_timeout_tick(tmo);
ttp = odp_timeout_user_ptr(tmo);
- ttp->buf = odp_buffer_from_event(ev);
+ ttp->ev = ev;
if (!odp_timeout_fresh(tmo)) {
/* Not the expected expiration tick, timer has
* been reset or cancelled or freed */
@@ -154,12 +156,12 @@ static void test_abs_timeouts(int thr, test_args_t *args)
}
/* Cancel and free last timer used */
- (void)odp_timer_cancel(ttp->tim, &ttp->buf);
- if (ttp->buf != ODP_BUFFER_INVALID)
- odp_buffer_free(ttp->buf);
+ (void)odp_timer_cancel(ttp->tim, &ttp->ev);
+ if (ttp->ev != ODP_EVENT_INVALID)
+ odp_buffer_free(odp_buffer_from_event(ttp->ev));
else
- EXAMPLE_ERR("Lost timeout buffer at timer cancel\n");
- /* Since we have cancelled the timer, there is no timeout buffer to
+ EXAMPLE_ERR("Lost timeout event at timer cancel\n");
+ /* Since we have cancelled the timer, there is no timeout event to
* return from odp_timer_free() */
(void)odp_timer_free(ttp->tim);
}
@@ -20,7 +20,6 @@ extern "C" {
#include <stdlib.h>
#include <odp_std_types.h>
-#include <odp_buffer.h>
#include <odp_event.h>
#include <odp_queue.h>
@@ -86,10 +85,10 @@ typedef enum {
* timer pool. */
ODP_TIMER_TOOLATE = -2,
/**
- * Timer set operation failed because no timeout buffer specified and no
- * timeout buffer present in the timer (timer inactive/expired).
+ * Timer set operation failed because no timeout event specified and no
+ * timeout event present in the timer (timer inactive/expired).
*/
- ODP_TIMER_NOBUF = -3
+ ODP_TIMER_NOEVENT = -3
} odp_timer_set_t;
/** Maximum timer pool name length in chars (including null char) */
@@ -214,29 +213,29 @@ odp_timer_t odp_timer_alloc(odp_timer_pool_t tpid,
* Free a timer
*
* Free (destroy) a timer, reclaiming associated resources.
- * The timeout buffer for an active timer will be returned.
- * The timeout buffer for an expired timer will not be returned. It is the
+ * The timeout event for an active timer will be returned.
+ * The timeout event for an expired timer will not be returned. It is the
* responsibility of the application to handle this timeout when it is received.
*
* @param tim Timer handle
- * @return Buffer handle of timeout buffer or ODP_BUFFER_INVALID
+ * @return Event handle of timeout event or ODP_EVENT_INVALID
*/
-odp_buffer_t odp_timer_free(odp_timer_t tim);
+odp_event_t odp_timer_free(odp_timer_t tim);
/**
- * Set a timer (absolute time) with a user-provided timeout buffer
+ * Set a timer (absolute time) with a user-provided timeout event
*
* Set (arm) the timer to expire at specific time. The timeout
- * buffer will be enqueued when the timer expires.
+ * event will be enqueued when the timer expires.
*
* Note: any invalid parameters will be treated as programming errors and will
* cause the application to abort.
*
* @param tim Timer
* @param abs_tck Expiration time in absolute timer ticks
- * @param[in,out] tmo_buf Reference to a buffer variable that points to
- * timeout buffer or NULL to reuse the existing timeout buffer. Any existing
- * timeout buffer that is replaced by a successful set operation will be
+ * @param[in,out] tmo_ev Reference to an event variable that points to
+ * timeout event or NULL to reuse the existing timeout event. Any existing
+ * timeout event that is replaced by a successful set operation will be
* returned here.
*
* @retval ODP_TIMER_SUCCESS Operation succeeded
@@ -244,15 +243,15 @@ odp_buffer_t odp_timer_free(odp_timer_t tim);
* early
* @retval ODP_TIMER_TOOLATE Operation failed because expiration tick too
* late
- * @retval ODP_TIMER_NOBUF Operation failed because timeout buffer not
+ * @retval ODP_TIMER_NOEVENT Operation failed because timeout event not
* specified in odp_timer_set call and not present in timer
*/
int odp_timer_set_abs(odp_timer_t tim,
uint64_t abs_tck,
- odp_buffer_t *tmo_buf);
+ odp_event_t *tmo_ev);
/**
- * Set a timer with a relative expiration time and user-provided buffer.
+ * Set a timer with a relative expiration time and user-provided event.
*
* Set (arm) the timer to expire at a relative future time.
*
@@ -262,9 +261,9 @@ int odp_timer_set_abs(odp_timer_t tim,
* @param tim Timer
* @param rel_tck Expiration time in timer ticks relative to current time of
* the timer pool the timer belongs to
- * @param[in,out] tmo_buf Reference to a buffer variable that points to
- * timeout buffer or NULL to reuse the existing timeout buffer. Any existing
- * timeout buffer that is replaced by a successful set operation will be
+ * @param[in,out] tmo_ev Reference to an event variable that points to
+ * timeout event or NULL to reuse the existing timeout event. Any existing
+ * timeout event that is replaced by a successful set operation will be
* returned here.
*
* @retval ODP_TIMER_SUCCESS Operation succeeded
@@ -272,18 +271,18 @@ int odp_timer_set_abs(odp_timer_t tim,
* early
* @retval ODP_TIMER_TOOLATE Operation failed because expiration tick too
* late
- * @retval ODP_TIMER_NOBUF Operation failed because timeout buffer not
+ * @retval ODP_TIMER_NOEVENT Operation failed because timeout event not
* specified in call and not present in timer
*/
int odp_timer_set_rel(odp_timer_t tim,
uint64_t rel_tck,
- odp_buffer_t *tmo_buf);
+ odp_event_t *tmo_ev);
/**
* Cancel a timer
*
* Cancel a timer, preventing future expiration and delivery. Return any
- * present timeout buffer.
+ * present timeout event.
*
* A timer that has already expired may be impossible to cancel and the timeout
* will instead be delivered to the destination queue.
@@ -292,23 +291,11 @@ int odp_timer_set_rel(odp_timer_t tim,
* cause the application to abort.
*
* @param tim Timer
- * @param[out] tmo_buf Pointer to a buffer variable
- * @retval 0 Success, active timer cancelled, timeout returned in '*tmo_buf'
+ * @param[out] tmo_ev Pointer to an event variable
+ * @retval 0 Success, active timer cancelled, timeout returned in '*tmo_ev'
* @retval -1 Failure, timer already expired (or inactive)
*/
-int odp_timer_cancel(odp_timer_t tim, odp_buffer_t *tmo_buf);
-
-/**
- * Return timeout handle that is associated with timeout buffer
- *
- * Note: any invalid parameters will cause undefined behavior and may cause
- * the application to abort or crash.
- *
- * @param buf A buffer of type ODP_BUFFER_TYPE_TIMEOUT
- *
- * @return timeout handle
- */
-odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf);
+int odp_timer_cancel(odp_timer_t tim, odp_event_t *tmo_ev);
/**
* Return timeout handle that is associated with timeout event
@@ -316,7 +303,7 @@ odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf);
* Note: any invalid parameters will cause undefined behavior and may cause
* the application to abort or crash.
*
- * @param buf An event of type ODP_EVENT_TIMEOUT
+ * @param ev An event of type ODP_EVENT_TIMEOUT
*
* @return timeout handle
*/
@@ -739,17 +739,17 @@ odp_timer_t odp_timer_alloc(odp_timer_pool_t tpid,
return ODP_TIMER_INVALID;
}
-odp_buffer_t odp_timer_free(odp_timer_t hdl)
+odp_event_t odp_timer_free(odp_timer_t hdl)
{
odp_timer_pool *tp = handle_to_tp(hdl);
uint32_t idx = handle_to_idx(hdl, tp);
odp_buffer_t old_buf = timer_free(tp, idx);
- return old_buf;
+ return odp_buffer_to_event(old_buf);
}
int odp_timer_set_abs(odp_timer_t hdl,
uint64_t abs_tck,
- odp_buffer_t *tmo_buf)
+ odp_event_t *tmo_ev)
{
odp_timer_pool *tp = handle_to_tp(hdl);
uint32_t idx = handle_to_idx(hdl, tp);
@@ -758,15 +758,15 @@ int odp_timer_set_abs(odp_timer_t hdl,
return ODP_TIMER_TOOEARLY;
if (odp_unlikely(abs_tck > cur_tick + tp->max_rel_tck))
return ODP_TIMER_TOOLATE;
- if (timer_reset(idx, abs_tck, tmo_buf, tp))
+ if (timer_reset(idx, abs_tck, (odp_buffer_t *)tmo_ev, tp))
return ODP_TIMER_SUCCESS;
else
- return ODP_TIMER_NOBUF;
+ return ODP_TIMER_NOEVENT;
}
int odp_timer_set_rel(odp_timer_t hdl,
uint64_t rel_tck,
- odp_buffer_t *tmo_buf)
+ odp_event_t *tmo_ev)
{
odp_timer_pool *tp = handle_to_tp(hdl);
uint32_t idx = handle_to_idx(hdl, tp);
@@ -775,34 +775,26 @@ int odp_timer_set_rel(odp_timer_t hdl,
return ODP_TIMER_TOOEARLY;
if (odp_unlikely(rel_tck > tp->max_rel_tck))
return ODP_TIMER_TOOLATE;
- if (timer_reset(idx, abs_tck, tmo_buf, tp))
+ if (timer_reset(idx, abs_tck, (odp_buffer_t *)tmo_ev, tp))
return ODP_TIMER_SUCCESS;
else
- return ODP_TIMER_NOBUF;
+ return ODP_TIMER_NOEVENT;
}
-int odp_timer_cancel(odp_timer_t hdl, odp_buffer_t *tmo_buf)
+int odp_timer_cancel(odp_timer_t hdl, odp_event_t *tmo_ev)
{
odp_timer_pool *tp = handle_to_tp(hdl);
uint32_t idx = handle_to_idx(hdl, tp);
/* Set the expiration tick of the timer to TMO_INACTIVE */
odp_buffer_t old_buf = timer_cancel(tp, idx, TMO_INACTIVE);
if (old_buf != ODP_BUFFER_INVALID) {
- *tmo_buf = old_buf;
+ *tmo_ev = odp_buffer_to_event(old_buf);
return 0; /* Active timer cancelled, timeout returned */
} else {
return -1; /* Timer already expired, no timeout returned */
}
}
-odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf)
-{
- /* This check not mandated by the API specification */
- if (_odp_buffer_type(buf) != ODP_BUFFER_TYPE_TIMEOUT)
- ODP_ABORT("Buffer not a timeout");
- return (odp_timeout_t)timeout_hdr_from_buf(buf);
-}
-
odp_timeout_t odp_timeout_from_event(odp_event_t ev)
{
/* This check not mandated by the API specification */
Changed timer API to use odp_event_t instead of odp_buffer_t. Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org> --- example/timer/odp_timer_test.c | 28 ++++++------ platform/linux-generic/include/api/odp_timer.h | 63 ++++++++++---------------- platform/linux-generic/odp_timer.c | 28 ++++-------- 3 files changed, 50 insertions(+), 69 deletions(-)