OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [src/] [lib/] [idpool.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Used for thread and space ids.
3
 *
4
 * Copyright (C) 2007, 2008 Bahadir Balban
5
 */
6
#include <l4/lib/printk.h>
7
#include <l4/lib/idpool.h>
8
#include INC_GLUE(memory.h)
9
 
10
struct id_pool *id_pool_new_init(int totalbits, void *freebuf)
11
{
12
        int nwords = BITWISE_GETWORD(totalbits);
13
        struct id_pool *new = freebuf;
14
        // int bufsize = (nwords * SZ_WORD) + sizeof(struct id_pool);
15
 
16
        spin_lock_init(&new->lock);
17
        new->nwords = nwords;
18
        return new;
19
}
20
 
21
int id_new(struct id_pool *pool)
22
{
23
        int id;
24
 
25
        spin_lock(&pool->lock);
26
        id = find_and_set_first_free_bit(pool->bitmap,
27
                                             pool->nwords * WORD_BITS);
28
        spin_unlock(&pool->lock);
29
        BUG_ON(id < 0);
30
 
31
        return id;
32
}
33
 
34
int id_del(struct id_pool *pool, int id)
35
{
36
        int ret;
37
 
38
        spin_lock(&pool->lock);
39
        ret = check_and_clear_bit(pool->bitmap, id);
40
        spin_unlock(&pool->lock);
41
 
42
        BUG_ON(ret < 0);
43
        return ret;
44
}
45
 
46
/* Return a specific id, if available */
47
int id_get(struct id_pool *pool, int id)
48
{
49
        int ret;
50
 
51
        spin_lock(&pool->lock);
52
        ret = check_and_set_bit(pool->bitmap, id);
53
        spin_unlock(&pool->lock);
54
 
55
        if (ret < 0)
56
                return ret;
57
        else
58
                return id;
59
}
60
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.