xref: /haiku/src/system/libroot/os/arch/m68k/tls.c (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
1 /*
2 ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the MIT 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 #warning FIXME: M68K
11 
12 #include <runtime_loader/runtime_loader.h>
13 
14 #include "support/TLS.h"
15 #include "tls.h"
16 
17 
18 static int32 gNextSlot = TLS_FIRST_FREE_SLOT;
19 static void *gSlots[TLS_MAX_KEYS];
20 
21 struct tls_index {
22 	unsigned long int	module;
23 	unsigned long int	offset;
24 };
25 
26 void* __tls_get_addr(struct tls_index* ti);
27 
28 
29 int32
30 tls_allocate(void)
31 {
32 	int32 next = atomic_add(&gNextSlot, 1);
33 	if (next >= TLS_MAX_KEYS)
34 		return B_NO_MEMORY;
35 
36 	return next;
37 }
38 
39 
40 void *
41 tls_get(int32 index)
42 {
43 	return gSlots[index];
44 }
45 
46 
47 void **
48 tls_address(int32 index)
49 {
50 	return &gSlots[index];
51 }
52 
53 
54 void
55 tls_set(int32 index, void *value)
56 {
57 	gSlots[index] = value;
58 }
59 
60 void*
61 __tls_get_addr(struct tls_index* ti)
62 {
63 	return __gRuntimeLoader->get_tls_address(ti->module, ti->offset);
64 }
65 
66