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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [libl4/] [src/] [lib/] [thread/] [init.c] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
 
2
#include <l4lib/mutex.h>
3
#include <l4lib/lib/thread.h>
4
#include <memcache/memcache.h>
5
 
6
/*
7
 * Static stack and utcb for same-space threads.
8
 * +1 is a good approximation for allocating for bitmap
9
 * structures in the memcache.
10
 */
11
static char stack[THREADS_TOTAL * (STACK_SIZE + 1)] ALIGN(STACK_SIZE);
12
static char utcb[THREADS_TOTAL * (UTCB_SIZE + 1)] ALIGN(UTCB_SIZE);
13
 
14
struct mem_cache *utcb_cache;
15
struct mem_cache *stack_cache;
16
 
17
struct l4_thread_list l4_thread_list;
18
 
19
/* Number of thread structs + allowance for memcache internal data */
20
#define L4_THREAD_LIST_BUFFER_SIZE (THREADS_TOTAL * \
21
                                    (sizeof(struct l4_thread_list)) + 256)
22
 
23
static char l4_thread_list_buf[L4_THREAD_LIST_BUFFER_SIZE];
24
 
25
void l4_thread_list_init(void)
26
{
27
        struct l4_thread_list *tlist = &l4_thread_list;
28
 
29
        /* Initialize the head struct */
30
        memset(tlist, 0, sizeof (*tlist));
31
        link_init(&tlist->thread_list);
32
        l4_mutex_init(&tlist->lock);
33
 
34
        /* Initialize a cache of l4_thread_list structs */
35
        if (!(tlist->thread_cache =
36
              mem_cache_init(&l4_thread_list_buf,
37
                             L4_THREAD_LIST_BUFFER_SIZE,
38
                             sizeof(struct l4_thread), 0))) {
39
                printf("FATAL: Could not initialize internal "
40
                       "thread struct cache.\n");
41
                BUG();
42
        }
43
}
44
 
45
void l4_stack_alloc_init(void)
46
{
47
        BUG_ON(!(stack_cache =
48
                 mem_cache_init((void *)stack, STACK_SIZE *
49
                                (THREADS_TOTAL + 1),
50
                                STACK_SIZE, STACK_SIZE)));
51
}
52
 
53
/*
54
 * Initialize a memcache that is aligned to utcb size
55
 */
56
void l4_utcb_alloc_init(void)
57
{
58
        BUG_ON(!(utcb_cache =
59
                 mem_cache_init((void *)utcb, UTCB_SIZE *
60
                                (THREADS_TOTAL + 1),
61
                                UTCB_SIZE, UTCB_SIZE)));
62
}
63
 
64
void __l4_threadlib_init(void)
65
{
66
        l4_utcb_alloc_init();
67
        l4_stack_alloc_init();
68
        l4_thread_list_init();
69
        l4_parent_thread_init();
70
}
71
 

powered by: WebSVN 2.1.0

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