]> git.proxmox.com Git - ovs.git/blame - ofproto/ofproto-dpif-rid.c
dpif-netdev: Remove redundant hash action handling.
[ovs.git] / ofproto / ofproto-dpif-rid.c
CommitLineData
f5374617
AZ
1/*
2 * Copyright (c) 2014 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <config.h>
18
c3bd4bfc 19#include "id-pool.h"
f5374617
AZ
20#include "ovs-thread.h"
21#include "ofproto-dpif-rid.h"
22
f5374617
AZ
23struct recirc_id_pool {
24 struct ovs_mutex lock;
c3bd4bfc 25 struct id_pool *rids;
f5374617
AZ
26};
27
28#define RECIRC_ID_BASE 300
29#define RECIRC_ID_N_IDS 1024
30
f5374617
AZ
31struct recirc_id_pool *
32recirc_id_pool_create(void)
33{
34 struct recirc_id_pool *pool;
35
36 pool = xmalloc(sizeof *pool);
c3bd4bfc 37 pool->rids = id_pool_create(RECIRC_ID_BASE, RECIRC_ID_N_IDS);
f5374617
AZ
38 ovs_mutex_init(&pool->lock);
39
40 return pool;
41}
42
43void
44recirc_id_pool_destroy(struct recirc_id_pool *pool)
45{
c3bd4bfc 46 id_pool_destroy(pool->rids);
f5374617 47 ovs_mutex_destroy(&pool->lock);
6a5be730 48 free(pool);
f5374617
AZ
49}
50
51uint32_t
52recirc_id_alloc(struct recirc_id_pool *pool)
53{
54 uint32_t id;
27c24749 55 bool ret;
f5374617
AZ
56
57 ovs_mutex_lock(&pool->lock);
27c24749 58 ret = id_pool_alloc_id(pool->rids, &id);
f5374617
AZ
59 ovs_mutex_unlock(&pool->lock);
60
27c24749
SH
61 if (!ret) {
62 return 0;
63 }
64
f5374617
AZ
65 return id;
66}
67
68void
69recirc_id_free(struct recirc_id_pool *pool, uint32_t id)
70{
71 ovs_mutex_lock(&pool->lock);
c3bd4bfc 72 id_pool_free_id(pool->rids, id);
f5374617
AZ
73 ovs_mutex_unlock(&pool->lock);
74}