1 /*************************************************************************
3 * Thread local storage access stub for Open Dynamics Engine, *
4 * Copyright (C) 2008 Oleh Derevenko. All rights reserved. *
5 * Email: odar@eleks.com (change all "a" to "e") *
7 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
8 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
11 * This library is free software; you can redistribute it and/or *
12 * modify it under the terms of EITHER: *
13 * (1) The GNU Lesser General Public License as published by the Free *
14 * Software Foundation; either version 2.1 of the License, or (at *
15 * your option) any later version. The text of the GNU Lesser *
16 * General Public License is included with this library in the *
18 * (2) The BSD-style license that is included with this library in *
19 * the file LICENSE-BSD.TXT. *
21 * This library is distributed in the hope that it will be useful, *
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
24 * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
26 *************************************************************************/
30 ODE Thread Local Storage access stub implementation.
34 #include <ode/common.h>
35 #include <ode/odemath.h>
38 #include "collision_trimesh_internal.h"
43 //////////////////////////////////////////////////////////////////////////
44 // Class static fields
46 HTLSKEY
COdeTls::m_htkStorageKey
= 0;
49 //////////////////////////////////////////////////////////////////////////
50 // Initialization and finalization
52 bool COdeTls::Initialize(unsigned uFlags
/*=0*/)
54 unsigned uOUFlags
= 0;
56 if (uFlags
& MANUAL_DATA_CLEANUP
)
58 uOUFlags
|= CTLSInitialization::SIF_MANUAL_CLEANUP_ON_THREAD_EXIT
;
61 bool bResult
= CTLSInitialization::InitializeTLSAPI(m_htkStorageKey
, OTI__MAX
, uOUFlags
);
65 void COdeTls::Finalize()
67 CTLSInitialization::FinalizeTLSAPI();
73 void COdeTls::CleanupForThread()
75 CTLSInitialization::CleanupOnThreadExit();
79 //////////////////////////////////////////////////////////////////////////
82 bool COdeTls::AssignDataAllocationFlags(unsigned uInitializationFlags
)
84 bool bResult
= CThreadLocalStorage::SetStorageValue(m_htkStorageKey
, OTI_DATA_ALLOCATION_FLAGS
, (tlsvaluetype
)uInitializationFlags
);
89 bool COdeTls::AssignTrimeshCollidersCache(TrimeshCollidersCache
*pccInstance
)
91 dIASSERT(!CThreadLocalStorage::GetStorageValue(m_htkStorageKey
, OTI_TRIMESH_TRIMESH_COLLIDER_CACHE
));
93 bool bResult
= CThreadLocalStorage::SetStorageValue(m_htkStorageKey
, OTI_TRIMESH_TRIMESH_COLLIDER_CACHE
, (tlsvaluetype
)pccInstance
, &COdeTls::FreeTrimeshCollidersCache_Callback
);
97 void COdeTls::DestroyTrimeshCollidersCache()
99 TrimeshCollidersCache
*pccCacheInstance
= (TrimeshCollidersCache
*)CThreadLocalStorage::GetStorageValue(m_htkStorageKey
, OTI_TRIMESH_TRIMESH_COLLIDER_CACHE
);
101 if (pccCacheInstance
)
103 FreeTrimeshCollidersCache(pccCacheInstance
);
105 CThreadLocalStorage::UnsafeSetStorageValue(m_htkStorageKey
, OTI_TRIMESH_TRIMESH_COLLIDER_CACHE
, (tlsvaluetype
)NULL
);
110 bool COdeTls::AssignTrimeshCollisionLibraryData(void *pv_DataInstance
)
113 dIASSERT(!CThreadLocalStorage::GetStorageValue(m_htkStorageKey
, OTI_TRIMESH_COLLISION_LIBRARY_DATA
));
115 bool bResult
= CThreadLocalStorage::SetStorageValue(m_htkStorageKey
, OTI_TRIMESH_COLLISION_LIBRARY_DATA
, (tlsvaluetype
)pv_DataInstance
, &COdeTls::FreeTrimeshCollisionLibraryData_Callback
);
118 dIASSERT(false); // Should only be called when trimesh is enabled
123 void COdeTls::DestroyTrimeshCollisionLibraryData()
126 void *pv_DataInstance
= (void *)CThreadLocalStorage::GetStorageValue(m_htkStorageKey
, OTI_TRIMESH_COLLISION_LIBRARY_DATA
);
130 FreeTrimeshCollisionLibraryData(pv_DataInstance
);
132 CThreadLocalStorage::UnsafeSetStorageValue(m_htkStorageKey
, OTI_TRIMESH_COLLISION_LIBRARY_DATA
, (tlsvaluetype
)NULL
);
135 dIASSERT(false); // Should only be called when trimesh is enabled
140 //////////////////////////////////////////////////////////////////////////
141 // Value type destructors
143 void COdeTls::FreeTrimeshCollidersCache(TrimeshCollidersCache
*pccCacheInstance
)
145 delete pccCacheInstance
;
148 void COdeTls::FreeTrimeshCollisionLibraryData(void *pv_DataInstance
)
153 Opcode::ThreadLocalData
*pldOpcodeData
= (Opcode::ThreadLocalData
*)pv_DataInstance
;
154 delete pldOpcodeData
;
155 #endif // dTRIMESH_OPCODE
158 dIASSERT(false); // There is no library specific data for GIMPACT
159 #endif // dTRIMESH_GIMPACT
162 dIASSERT(false); // Should only be called when trimesh is enabled
167 //////////////////////////////////////////////////////////////////////////
168 // Value type destructor callbacks
170 void COdeTls::FreeTrimeshCollidersCache_Callback(tlsvaluetype vValueData
)
172 TrimeshCollidersCache
*pccCacheInstance
= (TrimeshCollidersCache
*)vValueData
;
173 FreeTrimeshCollidersCache(pccCacheInstance
);
176 void COdeTls::FreeTrimeshCollisionLibraryData_Callback(tlsvaluetype vValueData
)
179 void *pv_DataInstance
= (void *)vValueData
;
180 FreeTrimeshCollisionLibraryData(pv_DataInstance
);
182 dIASSERT(false); // Should only be called when trimesh is enabled
187 #endif // #if dTLS_ENABLED