5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Thread Local Storage (TSL), Generic Implementation.
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2008-2011 Oracle Corporation
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * available from http://www.virtualbox.org. This file is free software;
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * General Public License (GPL) as published by the Free Software
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * The contents of this file may alternatively be used under the terms
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * of the Common Development and Distribution License Version 1.0
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * VirtualBox OSE distribution, in which case the provisions of the
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * CDDL are applicable instead of those of the GPL.
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * You may elect to license modified versions of this file under the
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * terms and conditions of either the GPL or the CDDL or both.
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync/*******************************************************************************
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync* Header Files *
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync*******************************************************************************/
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync/*******************************************************************************
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync* Global Variables *
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync*******************************************************************************/
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync/** Allocation bitmap. Set bits indicates allocated entries. */
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsyncstatic uint32_t volatile g_au32AllocatedBitmap[(RTTHREAD_TLS_ENTRIES + 31) / 32];
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync/** Destructors for each of the TLS entries. */
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsyncstatic PFNRTTLSDTOR g_apfnDestructors[RTTHREAD_TLS_ENTRIES];
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsyncRTR3DECL(int) RTTlsAllocEx(PRTTLS piTls, PFNRTTLSDTOR pfnDestructor)
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync for (unsigned i = 0; i < 128; i++)
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync int iTls = ASMBitFirstClear(&g_au32AllocatedBitmap[0], RTTHREAD_TLS_ENTRIES);
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync if (!ASMAtomicBitTestAndSet(&g_au32AllocatedBitmap[0], iTls))
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync ASMAtomicBitClear(&g_au32AllocatedBitmap[0], iTls);
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsyncRTR3DECL(int) RTTlsGetEx(RTTLS iTls, void **ppvValue)
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync PRTTHREADINT pThread = rtThreadGet(RTThreadSelf());
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync PRTTHREADINT pThread = rtThreadGet(RTThreadSelf());
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * Called at thread termination to invoke TLS destructors.
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync * @param pThread The current thread.
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(void) rtThreadTlsDestruction(PRTTHREADINT pThread)
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync for (RTTLS iTls = 0; iTls < RTTHREAD_TLS_ENTRIES; iTls++)
b03b95de5c1e684012148dc2ae8aaaaeaa651313vboxsync PFNRTTLSDTOR pfnDestructor = (PFNRTTLSDTOR)(uintptr_t)ASMAtomicUoReadPtr((void * volatile *)(uintptr_t)&g_apfnDestructors[iTls]);