15af32e75SAxel Dörfler /* 25af32e75SAxel Dörfler ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3*b6f76ebeSAugustin Cavalier ** Distributed under the terms of the MIT License. 45af32e75SAxel Dörfler */ 55af32e75SAxel Dörfler 65af32e75SAxel Dörfler // ToDo: this is a dummy implementation - I've not yet gained enough knowledge 75af32e75SAxel Dörfler // to decide how this should be done, so it's just broken now (okay for single 85af32e75SAxel Dörfler // threaded apps, though). 95af32e75SAxel Dörfler 105af32e75SAxel Dörfler #include "support/TLS.h" 115af32e75SAxel Dörfler #include "tls.h" 125af32e75SAxel Dörfler 135af32e75SAxel Dörfler 145af32e75SAxel Dörfler static int32 gNextSlot = TLS_FIRST_FREE_SLOT; 155af32e75SAxel Dörfler static void *gSlots[TLS_MAX_KEYS]; 165af32e75SAxel Dörfler 175af32e75SAxel Dörfler 185af32e75SAxel Dörfler int32 tls_allocate(void)195af32e75SAxel Dörflertls_allocate(void) 205af32e75SAxel Dörfler { 215af32e75SAxel Dörfler int32 next = atomic_add(&gNextSlot, 1); 225af32e75SAxel Dörfler if (next >= TLS_MAX_KEYS) 235af32e75SAxel Dörfler return B_NO_MEMORY; 245af32e75SAxel Dörfler 255af32e75SAxel Dörfler return next; 265af32e75SAxel Dörfler } 275af32e75SAxel Dörfler 285af32e75SAxel Dörfler 295af32e75SAxel Dörfler void * tls_get(int32 index)305af32e75SAxel Dörflertls_get(int32 index) 315af32e75SAxel Dörfler { 325af32e75SAxel Dörfler return gSlots[index]; 335af32e75SAxel Dörfler } 345af32e75SAxel Dörfler 355af32e75SAxel Dörfler 365af32e75SAxel Dörfler void ** tls_address(int32 index)375af32e75SAxel Dörflertls_address(int32 index) 385af32e75SAxel Dörfler { 395af32e75SAxel Dörfler return &gSlots[index]; 405af32e75SAxel Dörfler } 415af32e75SAxel Dörfler 425af32e75SAxel Dörfler 435af32e75SAxel Dörfler void tls_set(int32 index,void * value)445af32e75SAxel Dörflertls_set(int32 index, void *value) 455af32e75SAxel Dörfler { 465af32e75SAxel Dörfler gSlots[index] = value; 475af32e75SAxel Dörfler } 485af32e75SAxel Dörfler 49