| 58 | static thread_key_struct thread_keys[THREAD_KEYS_MAX] = {}; |
| 59 | |
| 60 | int thread_key_create(thread_key_t* key, void (* destr)(void*)) { |
| 61 | for (uint64_t index = 0; index < THREAD_KEYS_MAX; ++index) { |
| 62 | /* Find a slot in thread_keys which is unused. */ |
| 63 | uint64_t seq = thread_keys[index].seq; |
| 64 | if (key_unused(seq) && key_usable(seq) && |
| 65 | __sync_bool_compare_and_swap(&thread_keys[index].seq, seq, seq + 1)) { |
| 66 | thread_keys[index].dtor = destr; |
| 67 | *key = index; |
| 68 | return 0; |
| 69 | } |
| 70 | } |
| 71 | return EAGAIN; |
| 72 | } |
| 73 | |
| 74 | void* thread_getspecific(thread_key_t key) { |
| 75 | auto tls = (thread_local_storage*) (((partial_thread*) CURRENT)->tls); |