From patchwork Sat Mar 29 02:56:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shukla X-Patchwork-Id: 27386 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2576D20062 for ; Sat, 29 Mar 2014 02:56:45 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id eb12sf20886683oac.11 for ; Fri, 28 Mar 2014 19:56:44 -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=GLv9pl2QPxOcPTpPXSxiHKPR1wnBHrRIvxMqCBk1OkQ=; b=Lyh/x34ockjFmtZQeh+FLsHJLw+GLrrvtRwwIYwuQ89ZFMpJ2p++/HiHTIgvxQd/xr ULVE6UET1lUf23Swd1UnITnKH+iKeAOSIP0diWptThYxgiDBSSeXPlAQKED3Y3sCyZJ1 vxPb82Wz4fCGs+ieL+cVBvgKHe/6hU/TzIxQA+f3cLn+hXZ6RzaS6IAR8rxGB9ZbN3uq Nc9rPv4ICH7289J3wB1PR5cMfFEuezLJC6a1Dh7h9jz2dHCUeqKKtUQn5PdxNipaTdML bhz8OR/tVmirfQLvXhmqrEcGMbeG9EAnA1G4qZ7UP9BHHhXB0PczUrCXg3z89iaM2PXy 32vA== X-Gm-Message-State: ALoCoQniMFwto4QEd3lYb4A9ZsaGGm72JEb6Y76PboAXHaVhwab/VLOKZ8yJFEcV3zvA0uHO2vCb X-Received: by 10.43.126.2 with SMTP id gu2mr4335579icc.0.1396061804880; Fri, 28 Mar 2014 19:56:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.50.79.199 with SMTP id l7ls725160igx.30.gmail; Fri, 28 Mar 2014 19:56:44 -0700 (PDT) X-Received: by 10.50.49.44 with SMTP id r12mr185346ign.41.1396061804579; Fri, 28 Mar 2014 19:56:44 -0700 (PDT) Received: from mail-ie0-f173.google.com (mail-ie0-f173.google.com [209.85.223.173]) by mx.google.com with ESMTPS id m10si8806526icu.97.2014.03.28.19.56.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 19:56:44 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.223.173 is neither permitted nor denied by best guess record for domain of santosh.shukla@linaro.org) client-ip=209.85.223.173; Received: by mail-ie0-f173.google.com with SMTP id rl12so5780836iec.18 for ; Fri, 28 Mar 2014 19:56:43 -0700 (PDT) X-Received: by 10.43.135.202 with SMTP id ih10mr10943646icc.22.1396061803873; Fri, 28 Mar 2014 19:56:43 -0700 (PDT) Received: from santosh-Latitude-E5530-non-vPro.hil-sjccahw.sjc.wayport.net (ip-64-134-223-31.public.wayport.net. [64.134.223.31]) by mx.google.com with ESMTPSA id c10sm8865398igj.17.2014.03.28.19.56.42 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 19:56:43 -0700 (PDT) From: Santosh Shukla To: lng-odp@linaro.org Cc: santosh shukla Subject: [lng-odp] [ODP/PATCH v3 1/2] timer:add cancel_tmo function Date: Fri, 28 Mar 2014 19:56:29 -0700 Message-Id: <1396061790-26705-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.223.173 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. v3 change: - moved tmo_buf free to application layer. - changed serach and delete logic. platform/linux-generic/source/odp_timer.c | 63 ++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/source/odp_timer.c b/platform/linux-generic/source/odp_timer.c index 4bcc479..890dffb 100644 --- a/platform/linux-generic/source/odp_timer.c +++ b/platform/linux-generic/source/odp_timer.c @@ -92,6 +92,67 @@ static timeout_t *rem_tmo(tick_t *tick) } +static int find_and_del_tmo(timeout_t *tmo, odp_timer_tmo_t handle) +{ + timeout_t *cur, *prev; + prev = NULL; + + for (cur = tmo; cur != NULL; prev = cur, cur = cur->next) { + if (cur->tmo_buf == handle) + break; + } + + if (prev == NULL) + tmo = cur->next; + else + prev->next = cur->next; + + if (!cur) { + ODP_ERR("Couldn't find the tmo handle (%d)\n", handle); + return -1; + } + + /* free tmo buf .. application to free */ + + 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 tick_idx; + timeout_t *cancel_tmo; + tick_t *tick; + + /* get id */ + id = timer - 1; + + /* get tmo_buf to cancel */ + cancel_tmo = (timeout_t *)odp_buffer_addr(tmo); + tick_idx = cancel_tmo->tick; + tick = &odp_timer.timer[id].tick[tick_idx]; + + 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, tick_idx); + odp_spinlock_unlock(&tick->lock); + return -1; + } + odp_spinlock_unlock(&tick->lock); + + return 0; +} + static void notify_function(union sigval sigval) { @@ -167,8 +228,6 @@ int odp_timer_init_global(void) odp_spinlock_init(&odp_timer.timer[0].tick[i].lock); timer_init(); - - return 0; }