From patchwork Mon Dec 15 17:09:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42268 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4667026C6C for ; Mon, 15 Dec 2014 17:10:59 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf7653635lbj.3 for ; Mon, 15 Dec 2014 09:10:58 -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:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=UQs0teJmQ8AQeicV5p3NhXzXnikBri7AEkaGL4hBU7s=; b=EqoW53CI6kDWvfgJLBcf1hXx2WLANqeOTdxPf/FGrVOh7rPVWYc6iGC4mAysNdBec4 mToeFgDI8Vo11kLeBtmQNl2jznjALuyRtk9zkEW6XPxTZJ9AhXp6HS2JUm15D2tg7eM3 B07rkjHHep0b4WxusbP+BMPMtKjzZU72Nl9SV1utPhjVFlhwQYhkolqzJJQftAb6c2ko om++2pCl8ro7UxxfjpD90qfV3Ap90wjA/7EgnzGes92PAL6MLfuhBIEpuRAeZGycLH6F 4Wa+Vb7kOlukwRNHsnwDEL7Tg7HHs7jnM5WwfrhNUVtjq2HT3f6bIXwB4s/tHeXc8qxy dTYg== X-Gm-Message-State: ALoCoQkNVHlSfpaSSUjePF3OW9zFzgWr2QDTC2bwIvOmdhEzokE/8Y7cjwFtD1ur6dr9q5ivZjab X-Received: by 10.112.142.36 with SMTP id rt4mr4858915lbb.3.1418663458156; Mon, 15 Dec 2014 09:10:58 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.6.5 with SMTP id cq5ls770529lad.93.gmail; Mon, 15 Dec 2014 09:10:58 -0800 (PST) X-Received: by 10.153.5.33 with SMTP id cj1mr31860021lad.65.1418663458011; Mon, 15 Dec 2014 09:10:58 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id jo17si11080984lab.19.2014.12.15.09.10.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 15 Dec 2014 09:10:58 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id w7so5261035lbi.16 for ; Mon, 15 Dec 2014 09:10:57 -0800 (PST) X-Received: by 10.112.131.1 with SMTP id oi1mr23655385lbb.2.1418663457929; Mon, 15 Dec 2014 09:10:57 -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.142.69 with SMTP id ru5csp782108lbb; Mon, 15 Dec 2014 09:10:57 -0800 (PST) X-Received: by 10.140.84.197 with SMTP id l63mr5826906qgd.100.1418663456337; Mon, 15 Dec 2014 09:10:56 -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 u7si11325916qaj.5.2014.12.15.09.10.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 15 Dec 2014 09:10:56 -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 1Y0ZAb-0000vW-Px; Mon, 15 Dec 2014 17:10:53 +0000 Received: from mail-lb0-f182.google.com ([209.85.217.182]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0Z9y-0000bo-5d for lng-odp@lists.linaro.org; Mon, 15 Dec 2014 17:10:14 +0000 Received: by mail-lb0-f182.google.com with SMTP id f15so10148774lbj.41 for ; Mon, 15 Dec 2014 09:10:08 -0800 (PST) X-Received: by 10.112.168.164 with SMTP id zx4mr23072385lbb.28.1418663408503; Mon, 15 Dec 2014 09:10:08 -0800 (PST) Received: from localhost.localdomain ([80.77.38.170]) by mx.google.com with ESMTPSA id l9sm1208585lae.0.2014.12.15.09.10.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Dec 2014 09:10:07 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Mon, 15 Dec 2014 19:09:50 +0200 Message-Id: <1418663392-28354-6-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418663392-28354-1-git-send-email-taras.kondratiuk@linaro.org> References: <1418663392-28354-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv6 5/7] api: buffer: add pool destroy 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: taras.kondratiuk@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.171 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: Bill Fischofer Signed-off-by: Bill Fischofer Signed-off-by: Taras Kondratiuk --- .../linux-generic/include/api/odp_buffer_pool.h | 18 ++++++++++++ platform/linux-generic/odp_buffer_pool.c | 34 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/platform/linux-generic/include/api/odp_buffer_pool.h b/platform/linux-generic/include/api/odp_buffer_pool.h index 4ccdfe6..312b5f6 100644 --- a/platform/linux-generic/include/api/odp_buffer_pool.h +++ b/platform/linux-generic/include/api/odp_buffer_pool.h @@ -76,6 +76,24 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, odp_shm_t shm, odp_buffer_pool_param_t *params); +/** + * Destroy a buffer pool previously created by odp_buffer_pool_create() + * + * @param pool Handle of the buffer pool to be destroyed + * + * @retval 0 Success + * @retval -1 Failure + * + * @note This routine destroys a previously created buffer pool. This call + * does not destroy any shared memory object passed to + * odp_buffer_pool_create() used to store the buffer pool contents. The caller + * takes responsibility for that. If no shared memory object was passed as + * part of the create call, then this routine will destroy any internal shared + * memory objects associated with the buffer pool. Results are undefined if + * an attempt is made to destroy a buffer pool that contains allocated or + * otherwise active buffers. + */ +int odp_buffer_pool_destroy(odp_buffer_pool_t pool); /** * Find a buffer pool by name diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c index f19bee0..e2511af 100644 --- a/platform/linux-generic/odp_buffer_pool.c +++ b/platform/linux-generic/odp_buffer_pool.c @@ -390,6 +390,40 @@ odp_buffer_pool_t odp_buffer_pool_lookup(const char *name) return ODP_BUFFER_POOL_INVALID; } +int odp_buffer_pool_destroy(odp_buffer_pool_t pool_hdl) +{ + uint32_t pool_id = pool_handle_to_index(pool_hdl); + pool_entry_t *pool = get_pool_entry(pool_id); + + if (pool == NULL) + return -1; + + POOL_LOCK(&pool->s.lock); + + /* Call fails if pool is not allocated or predefined*/ + if (pool->s.pool_shm == ODP_SHM_INVALID || + pool->s.flags.predefined) { + POOL_UNLOCK(&pool->s.lock); + return -1; + } + + /* Make sure local cache is empty */ + flush_cache(&local_cache[pool_id], &pool->s); + + /* Call fails if pool has allocated buffers */ + if (odp_atomic_load_u32(&pool->s.bufcount) < pool->s.params.num_bufs) { + POOL_UNLOCK(&pool->s.lock); + return -1; + } + + if (!pool->s.flags.user_supplied_shm) + odp_shm_free(pool->s.pool_shm); + + pool->s.pool_shm = ODP_SHM_INVALID; + POOL_UNLOCK(&pool->s.lock); + + return 0; +} odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl, size_t size) {