Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6536 | serge | 1 | #include |
2 | |||
3 | static int tls_map[128/4]; |
||
4 | static int *tls_scan_start = tls_map; |
||
5 | static mutex_t tls_mutex; |
||
6 | |||
7 | void tls_init() |
||
8 | { |
||
9 | int i; |
||
10 | |||
11 | mutex_init(&tls_mutex); |
||
12 | |||
13 | tls_map[0] = 0xE0; |
||
14 | |||
15 | for(i = 1; i < 128/4; i++) |
||
16 | tls_map[i] = -1; |
||
17 | }; |
||
18 | |||
19 | int tls_free(unsigned int key) |
||
20 | { |
||
21 | int retval = -1; |
||
22 | |||
23 | if(key < 4096) |
||
24 | { |
||
25 | mutex_lock(&tls_mutex); |
||
26 | |||
27 | __asm__ volatile( |
||
28 | "shrl $2, %0 \n\t" |
||
29 | "btsl %0, (%1) \n\t" |
||
30 | ::"r"(key),"d"(tls_map) |
||
31 | :"cc","memory"); |
||
32 | tls_scan_start = &tls_map[key>>5]; |
||
33 | mutex_unlock(&tls_mutex); |
||
34 | retval = 0; |
||
35 | } |
||
36 | return retval; |
||
37 | }; |
||
38 | |||
39 | |||
40 | unsigned int tls_alloc() |
||
41 | { |
||
42 | unsigned int key; |
||
43 | |||
44 | mutex_lock(&tls_mutex); |
||
45 | |||
46 | __asm__ volatile( |
||
47 | "1: \n\t" |
||
48 | "bsfl (%1), %0 \n\t" |
||
49 | "jnz 2f \n\t" |
||
50 | "add $4, %1 \n\t" |
||
51 | "cmpl $128+_tls_map, %1 \n\t" |
||
52 | "jb 1b \n\t" |
||
53 | "xorl %0, %0 \n\t" |
||
54 | "notl %0 \n\t" |
||
55 | "jmp 3f \n\t" |
||
56 | "2: \n\t" |
||
57 | "btrl %0, (%1) \n\t" |
||
58 | "subl $_tls_map, %1 \n\t" |
||
59 | "leal (%0, %1, 8), %%eax \n\t" |
||
60 | "shll $2, %0 \n\t" |
||
61 | "3:" |
||
62 | :"=r"(key),"=d"(tls_scan_start) |
||
63 | :"d"(tls_scan_start) |
||
64 | :"cc","memory"); |
||
65 | |||
66 | mutex_unlock(&tls_mutex); |
||
67 | |||
68 | return key; |
||
69 | }>> |