2 * Copyright (c) 2014 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "ovs-thread.h"
21 #include "ofproto-dpif-rid.h"
23 struct recirc_id_pool {
24 struct ovs_mutex lock;
28 #define RECIRC_ID_BASE 300
29 #define RECIRC_ID_N_IDS 1024
31 struct recirc_id_pool *
32 recirc_id_pool_create(void)
34 struct recirc_id_pool *pool;
36 pool = xmalloc(sizeof *pool);
37 pool->rids = id_pool_create(RECIRC_ID_BASE, RECIRC_ID_N_IDS);
38 ovs_mutex_init(&pool->lock);
44 recirc_id_pool_destroy(struct recirc_id_pool *pool)
46 id_pool_destroy(pool->rids);
47 ovs_mutex_destroy(&pool->lock);
52 recirc_id_alloc(struct recirc_id_pool *pool)
57 ovs_mutex_lock(&pool->lock);
58 ret = id_pool_alloc_id(pool->rids, &id);
59 ovs_mutex_unlock(&pool->lock);
69 recirc_id_free(struct recirc_id_pool *pool, uint32_t id)
71 ovs_mutex_lock(&pool->lock);
72 id_pool_free_id(pool->rids, id);
73 ovs_mutex_unlock(&pool->lock);