From patchwork Tue Nov 18 13:39:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 41028 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8E04324035 for ; Tue, 18 Nov 2014 13:40:05 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf2485073wib.2 for ; Tue, 18 Nov 2014 05:40:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=eHoqResucoWrN3sWE0ZUGNkjZurndY1AuGS7theu9tI=; b=VhDE1YlNkacPEwNA9ktPFtvvPIhKIOMVPyoIdHYZESmw5YEtsYhuzH0Id5wy/gM93b ZfL/JWj+xEF0bqjIwrosSybRF+PxtUx1/1iT9vEgm9Vend4niQ8keNeuxL58MAeTyjgi CQz3TrkAAgKe6LJnUX3KoPsRawquA2QYKjQu9iKQyxpq6mdVLc0juzlV7LXxRsDTy3os zJMp/3OC4oiWRxhPQUV2mLJ3ibXPadbtY4UZGk0/7nUfKy9zzm+b1aELefGsne0PEHX/ 6xj9uujAjh41vCBXnK079s7XWe1VogmANZ6+rzJufUxKTxU2aiIKwfYrKoMKGUeSZLdG lcEw== X-Gm-Message-State: ALoCoQnA9j32tGjkQJdCXDdq37QwGRiWL++AjjHbbTmomhaERZnmyh0bbUzOk/EznJR5r00wjycm X-Received: by 10.112.138.234 with SMTP id qt10mr2077094lbb.4.1416318004757; Tue, 18 Nov 2014 05:40:04 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.197.100 with SMTP id it4ls1330196lac.7.gmail; Tue, 18 Nov 2014 05:40:04 -0800 (PST) X-Received: by 10.112.92.203 with SMTP id co11mr17222773lbb.79.1416318004588; Tue, 18 Nov 2014 05:40:04 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id s10si55817009lal.38.2014.11.18.05.40.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 05:40:04 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id w7so9202627lbi.33 for ; Tue, 18 Nov 2014 05:40:04 -0800 (PST) X-Received: by 10.112.45.102 with SMTP id l6mr7079308lbm.46.1416318004457; Tue, 18 Nov 2014 05:40:04 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp1328957lbc; Tue, 18 Nov 2014 05:40:03 -0800 (PST) X-Received: by 10.140.48.11 with SMTP id n11mr43155669qga.1.1416318003211; Tue, 18 Nov 2014 05:40:03 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id 1si13847929qau.29.2014.11.18.05.40.02 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 18 Nov 2014 05:40:03 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xqj0i-0008Gj-Sc; Tue, 18 Nov 2014 13:40:00 +0000 Received: from mail-pd0-f169.google.com ([209.85.192.169]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xqj0c-0008Gd-D4 for lng-odp@lists.linaro.org; Tue, 18 Nov 2014 13:39:54 +0000 Received: by mail-pd0-f169.google.com with SMTP id fp1so6028796pdb.14 for ; Tue, 18 Nov 2014 05:39:48 -0800 (PST) X-Received: by 10.68.87.37 with SMTP id u5mr11642425pbz.128.1416317988829; Tue, 18 Nov 2014 05:39:48 -0800 (PST) Received: from ysm-linux.localdomain ([223.65.189.196]) by mx.google.com with ESMTPSA id a6sm1217051pbu.64.2014.11.18.05.39.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Nov 2014 05:39:47 -0800 (PST) From: Yan Songming To: lng-odp@lists.linaro.org Date: Tue, 18 Nov 2014 21:39:30 +0800 Message-Id: <1416317970-6588-1-git-send-email-yan.songming@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Topics: patch Cc: Yan Sonming Subject: [lng-odp] [PATCH] add implement for odp_shm_free X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: yan.songming@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Yan Sonming New API implementing odp_shm_free to match the odp_shm_reserve. Signed-off-by: Yan Songming --- platform/linux-generic/odp_shared_memory.c | 42 +++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 24a5d60..fd8f698 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -114,6 +114,42 @@ static int find_block(const char *name, uint32_t *index) return 0; } +int odp_shm_free(odp_shm_t shm) +{ + uint32_t i; + int ret; + odp_shm_block_t *shm_block; + i = from_handle(shm); + uint64_t alloc_size; + if (odp_shm_tbl->block[i].addr == NULL) { + /* free block */ + ODP_DBG("odp_shm_free: Free block failed\n"); + return 0; + } + + odp_spinlock_lock(&odp_shm_tbl->lock); + shm_block = &odp_shm_tbl->block[i]; + + alloc_size = shm_block->size + shm_block->align; + ret = munmap(shm_block->addr, alloc_size); + if (0 != ret) { + ODP_DBG("odp_shm_free: munmap failed\n"); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return -1; + } + + if (shm_block->flags & ODP_SHM_PROC) { + ret = shm_unlink(shm_block->name); + if (0 != ret) { + ODP_DBG("odp_shm_free: shm_unlink failed\n"); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return -1; + } + } + memset(&odp_shm_tbl->block[i], 0, sizeof(odp_shm_block_t)); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return 0; +} odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags) @@ -221,12 +257,6 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, return block->hdl; } -int odp_shm_free(odp_shm_t shm ODP_UNUSED) -{ - ODP_UNIMPLEMENTED(); - return 0; -} - odp_shm_t odp_shm_lookup(const char *name) { uint32_t i;