From patchwork Thu Mar 27 20:20:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shukla X-Patchwork-Id: 27234 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B2696202FA for ; Thu, 27 Mar 2014 20:20:14 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id bj1sf9718896pad.3 for ; Thu, 27 Mar 2014 13:20:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe:content-type; bh=qir5cqrkwsCcQMebqHFY3EBz2yqFx4InDlHBqSdQ+8w=; b=TDO201/Ci+QLQ5khzv8v1Ng8zbO4koryVxkwJYh/8Rut0gCaqeyQpNZiG8IQShA3+x nzJeHA6Z/pE8MAMUYdzYgOHAJHfbwqNthwzFAFS/DEszFOKHwUxU9DMtRQGWypytrj1o 0CIjpcaqLrlyMr214GMc88kyNUUgwxWQmAxPQbmSoMEmq8GkQZuA0eQkUqgTlksrH8l0 R3goPulAfiHU/9jUSJ6mxzqtDAt2N+tAMISSe2RwB7dWrDuxq1H6jMO+dx4GWe4IZ+JR O5pSU6EjB2HgQqsvMOW6c9en1HFAV3PZM8XiDT0Gwdo6S2Af2tS/2GK0HZXc20lvPzAP rcjA== X-Gm-Message-State: ALoCoQmuxYvhnSMq40Yg9P10wz3R4YWHUBsnjL9TUwzS+r6qZFFt7FL5CXZKNzKntH48MeBsAYf/ X-Received: by 10.66.144.228 with SMTP id sp4mr1508154pab.5.1395951613608; Thu, 27 Mar 2014 13:20:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.50.62.15 with SMTP id u15ls1794713igr.37.gmail; Thu, 27 Mar 2014 13:20:13 -0700 (PDT) X-Received: by 10.66.121.164 with SMTP id ll4mr3891833pab.129.1395951613269; Thu, 27 Mar 2014 13:20:13 -0700 (PDT) Received: from mail-pd0-f179.google.com (mail-pd0-f179.google.com [209.85.192.179]) by mx.google.com with ESMTPS id qj1si2237477pbb.299.2014.03.27.13.20.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Mar 2014 13:20:13 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.179 is neither permitted nor denied by best guess record for domain of santosh.shukla@linaro.org) client-ip=209.85.192.179; Received: by mail-pd0-f179.google.com with SMTP id w10so3845335pde.38 for ; Thu, 27 Mar 2014 13:20:12 -0700 (PDT) X-Received: by 10.68.231.196 with SMTP id ti4mr4099007pbc.48.1395951612853; Thu, 27 Mar 2014 13:20:12 -0700 (PDT) Received: from santosh-Latitude-E5530-non-vPro.mvista.com (64.2.3.195.ptr.us.xo.net. [64.2.3.195]) by mx.google.com with ESMTPSA id zb2sm13017759pbc.30.2014.03.27.13.20.12 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Mar 2014 13:20:12 -0700 (PDT) From: Santosh Shukla To: lng-odp@linaro.org Cc: santosh shukla Subject: [lng-odp] [ODP/PATCHi v2 1/2] timer:add cancel_tmo function Date: Thu, 27 Mar 2014 13:20:04 -0700 Message-Id: <1395951605-3931-1-git-send-email-santosh.shukla@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Original-Sender: santosh.shukla@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.192.179 is neither permitted nor denied by best guess record for domain of santosh.shukla@linaro.org) smtp.mail=santosh.shukla@linaro.org Precedence: list Mailing-list: list lng-odp@linaro.org; contact lng-odp+owners@linaro.org List-ID: X-Google-Group-Id: 474323889996 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: santosh shukla Signed-off-by: santosh shukla --- v2 change: - added find and delete function so to delete only tmo not the entire list. platform/linux-generic/source/odp_timer.c | 62 ++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/source/odp_timer.c b/platform/linux-generic/source/odp_timer.c index 4bcc479..ce405a5 100644 --- a/platform/linux-generic/source/odp_timer.c +++ b/platform/linux-generic/source/odp_timer.c @@ -91,6 +91,66 @@ static timeout_t *rem_tmo(tick_t *tick) return tmo; } +static int find_and_del_tmo(timeout_t *tmo, odp_timer_tmo_t handle) +{ + timeout_t *del; + + for (; tmo; tmo = tmo->next) { + if (tmo->tmo_buf == handle) + break; + } + + if (!tmo) { + ODP_ERR("Couldn't find the tmo handle (%d)\n", handle); + return -1; + } + + del = tmo; + tmo = del->next; + odp_buffer_free(del->tmo_buf); + + return 0; +} + + +/** + * Cancel a timeout + * + * @param timer Timer + * @param tmo Timeout to cancel + * + * @return 0 if successful + */ +int odp_timer_cancel_tmo(odp_timer_t timer, odp_timer_tmo_t tmo) +{ + int id; + uint64_t abs_tick; + timeout_t *new_tmo; + tick_t *tick; + + /* get id */ + id = timer - 1; + + /* get tmo_buf to cancel */ + new_tmo = (timeout_t *)odp_buffer_addr(tmo); + new_tmo->tmo_tick = 0; /* reset tmo */ + abs_tick = new_tmo->tick; /* get the absolute + tick setted by prev add_tmo call */ + + tick = &odp_timer.timer[id].tick[abs_tick]; + + odp_spinlock_lock(&tick->lock); + + /* search and delete tmo from tick list */ + if (find_and_del_tmo(tick->list, tmo) != 0) { + ODP_ERR("cancel failed for tim id %d tmo id :%d tick idx %lu\n", id, tmo, abs_tick); + odp_spinlock_unlock(&tick->lock); + return -1; + } + odp_spinlock_unlock(&tick->lock); + + return 0; +} static void notify_function(union sigval sigval) @@ -167,8 +227,6 @@ int odp_timer_init_global(void) odp_spinlock_init(&odp_timer.timer[0].tick[i].lock); timer_init(); - - return 0; }