xref: /haiku/src/system/libroot/os/arch/ppc/tls.c (revision 3e216965baa8d58a67bf7372e2bfa13d999f5a9d)
1 /*
2 ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the OpenBeOS License.
4 */
5 
6 // ToDo: this is a dummy implementation - I've not yet gained enough knowledge
7 //	to decide how this should be done, so it's just broken now (okay for single
8 //	threaded apps, though).
9 
10 // we don't want to have the inline assembly included here
11 #ifndef _NO_INLINE_ASM
12 #	define _NO_INLINE_ASM 1
13 #endif
14 
15 #include "support/TLS.h"
16 #include "tls.h"
17 
18 
19 static int32 gNextSlot = TLS_FIRST_FREE_SLOT;
20 static void *gSlots[TLS_MAX_KEYS];
21 
22 
23 int32
24 tls_allocate(void)
25 {
26 	int32 next = atomic_add(&gNextSlot, 1);
27 	if (next >= TLS_MAX_KEYS)
28 		return B_NO_MEMORY;
29 
30 	return next;
31 }
32 
33 
34 void *
35 tls_get(int32 index)
36 {
37 	return gSlots[index];
38 }
39 
40 
41 void **
42 tls_address(int32 index)
43 {
44 	return &gSlots[index];
45 }
46 
47 
48 void
49 tls_set(int32 index, void *value)
50 {
51 	gSlots[index] = value;
52 }
53 
54