From patchwork Wed Nov 19 13:59:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 41162 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A635520CBB for ; Wed, 19 Nov 2014 14:00:32 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id l15sf743660wiw.0 for ; Wed, 19 Nov 2014 06:00:32 -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: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=s/okzc/dV0ahmYdIBWoftFk9bwlK7szRur/olUYksxQ=; b=G/r7M46PU7f7tZWsixzg+2fIbFpgBu4leYpXouUNxD0TwRK6ck/5eg6Hr/cci4WxsM MXAaxGT/Odm0FxxTOcWJGkLJ3L2rwSQUGNP3VhpIuWpbZnwmPV9saB7TAtosdNJTlizL fATR/18Q1WNhNk+W3HWTmAdaMwlii6ahDj6spXS+iTw6Ao2lWZm6mmSgcu8ef5F91qrX voQoHih5zWP9Vt8mM4OoQlmMED5LB7Kq0TCdCfIMbJapwz+sRWErqU+m1cHmhkZbS76k POWh8hOAFJYN0sOr9tXs2Rx87yrrPWSsyEGbQ52ffDR8kSi6oUUYIjkPGhCtlLMDWLCr M+Kg== X-Gm-Message-State: ALoCoQnnvdBI5/9CBVtrXPzgkq7V+9hVaw+fGSu3E1B+/i+ktYe1oDoaUIl9jTfJkMZ5mpAD135q X-Received: by 10.181.13.147 with SMTP id ey19mr5314734wid.2.1416405631989; Wed, 19 Nov 2014 06:00:31 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.138 with SMTP id q10ls1455227laj.83.gmail; Wed, 19 Nov 2014 06:00:31 -0800 (PST) X-Received: by 10.152.43.229 with SMTP id z5mr2245694lal.86.1416405631737; Wed, 19 Nov 2014 06:00:31 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id ro8si1883609lbb.75.2014.11.19.06.00.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Nov 2014 06:00:31 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id f15so582374lbj.13 for ; Wed, 19 Nov 2014 06:00:31 -0800 (PST) X-Received: by 10.112.45.102 with SMTP id l6mr5500087lbm.46.1416405631623; Wed, 19 Nov 2014 06:00:31 -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 ew9csp86405lbc; Wed, 19 Nov 2014 06:00:30 -0800 (PST) X-Received: by 10.170.32.82 with SMTP id 79mr41883335yka.26.1416405630281; Wed, 19 Nov 2014 06:00:30 -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 ce9si2261984qcb.21.2014.11.19.06.00.29 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Nov 2014 06:00:30 -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 1Xr5o3-0005bN-Hf; Wed, 19 Nov 2014 14:00:27 +0000 Received: from mail-pd0-f176.google.com ([209.85.192.176]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xr5nx-0005Zr-8Q for lng-odp@lists.linaro.org; Wed, 19 Nov 2014 14:00:21 +0000 Received: by mail-pd0-f176.google.com with SMTP id y10so848077pdj.21 for ; Wed, 19 Nov 2014 06:00:15 -0800 (PST) X-Received: by 10.68.130.136 with SMTP id oe8mr10960554pbb.121.1416405615246; Wed, 19 Nov 2014 06:00:15 -0800 (PST) Received: from ysm-linux.localdomain ([223.65.50.73]) by mx.google.com with ESMTPSA id oq6sm1928634pdb.45.2014.11.19.06.00.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Nov 2014 06:00:13 -0800 (PST) From: Yan Songming To: lng-odp@lists.linaro.org Date: Wed, 19 Nov 2014 21:59:58 +0800 Message-Id: <1416405598-12262-1-git-send-email-yan.songming@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Topics: patch Subject: [lng-odp] [PATCH v2] 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.182 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 New API implementing odp_shm_free to match the odp_shm_reserve. Signed-off-by: Yan Songming --- v2 fix the problem which Maxim found. --- platform/linux-generic/odp_shared_memory.c | 43 +++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 24a5d60..a1321bf 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -114,6 +114,43 @@ 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; + uint64_t alloc_size; + + i = from_handle(shm); + 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 +258,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;