1 #include "threadimpl.h"
7 struct thread_tag *next;
13 static spinlock_t mlock;
14 static spinlock_t dl_lock;
15 static spinlock_t tag_lock;
16 static struct thread_tag *thread_tag_store = nil;
17 static uint nextkey = 0;
20 _thread_malloc_lock(void)
26 _thread_malloc_unlock(void)
32 _thread_malloc_init(void)
40 _thread_dl_lock(int t)
43 _spinunlock(&dl_lock);
52 _thread_tag_init(void **tag)
58 t = malloc(sizeof (*t));
60 memset(&t->l, 0, sizeof(t->l));
65 _spinunlock(&tag_lock);
69 _thread_tag_lock(void **tag)
74 _thread_tag_init(tag);
80 _thread_tag_unlock(void **tag)
85 _thread_tag_init(tag);
91 _thread_tag_insert(struct thread_tag *t, void *v)
94 t->next = thread_tag_store;
100 _thread_tag_lookup(struct thread_tag *tag, int size)
102 struct thread_tag *t;
106 for(t = thread_tag_store; t != nil; t = t->next)
107 if(t->key == tag->key)
112 _spinunlock(&tag->l);
115 _thread_tag_insert(tag, p);
117 _spinunlock(&tag->l);
122 _thread_tag_storage(void **tag, void *storage, size_t n, void *err)
124 struct thread_tag *t;
128 _thread_tag_init(tag);
131 r = _thread_tag_lookup(t, n);
135 memcpy(r, storage, n);
143 dlctl(nil, DL_SETTHREADLCK, _thread_dl_lock);
144 signal(SIGUSR2, sigusr2handler);