Added: dSpaceSetSublevel/dSpaceGetSublevel and possibility to collide a space as...
[ode.git] / ode / src / odetls.cpp
blob710b0484695124bcbaa79436f03c541d635fff24
1 /*************************************************************************
2 * *
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") *
6 * *
7 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
8 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
9 * *
10 * *
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 *
17 * file LICENSE.TXT. *
18 * (2) The BSD-style license that is included with this library in *
19 * the file LICENSE-BSD.TXT. *
20 * *
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. *
25 * *
26 *************************************************************************/
30 ODE Thread Local Storage access stub implementation.
34 #include <ode/common.h>
35 #include <ode/odemath.h>
36 #include "config.h"
37 #include "odetls.h"
38 #include "collision_trimesh_internal.h"
41 #if dTLS_ENABLED
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);
62 return bResult;
65 void COdeTls::Finalize()
67 CTLSInitialization::FinalizeTLSAPI();
69 m_htkStorageKey = 0;
73 void COdeTls::CleanupForThread()
75 CTLSInitialization::CleanupOnThreadExit();
79 //////////////////////////////////////////////////////////////////////////
80 // Value modifiers
82 bool COdeTls::AssignDataAllocationFlags(unsigned uInitializationFlags)
84 bool bResult = CThreadLocalStorage::SetStorageValue(m_htkStorageKey, OTI_DATA_ALLOCATION_FLAGS, (tlsvaluetype)uInitializationFlags);
85 return bResult;
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);
94 return bResult;
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)
112 #if dTRIMESH_ENABLED
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);
116 return bResult;
117 #else
118 dIASSERT(false); // Should only be called when trimesh is enabled
119 return false;
120 #endif
123 void COdeTls::DestroyTrimeshCollisionLibraryData()
125 #if dTRIMESH_ENABLED
126 void *pv_DataInstance = (void *)CThreadLocalStorage::GetStorageValue(m_htkStorageKey, OTI_TRIMESH_COLLISION_LIBRARY_DATA);
128 if (pv_DataInstance)
130 FreeTrimeshCollisionLibraryData(pv_DataInstance);
132 CThreadLocalStorage::UnsafeSetStorageValue(m_htkStorageKey, OTI_TRIMESH_COLLISION_LIBRARY_DATA, (tlsvaluetype)NULL);
134 #else
135 dIASSERT(false); // Should only be called when trimesh is enabled
136 #endif
140 //////////////////////////////////////////////////////////////////////////
141 // Value type destructors
143 void COdeTls::FreeTrimeshCollidersCache(TrimeshCollidersCache *pccCacheInstance)
145 delete pccCacheInstance;
148 void COdeTls::FreeTrimeshCollisionLibraryData(void *pv_DataInstance)
150 #if dTRIMESH_ENABLED
152 #if dTRIMESH_OPCODE
153 Opcode::ThreadLocalData *pldOpcodeData = (Opcode::ThreadLocalData *)pv_DataInstance;
154 delete pldOpcodeData;
155 #endif // dTRIMESH_OPCODE
157 #if dTRIMESH_GIMPACT
158 dIASSERT(false); // There is no library specific data for GIMPACT
159 #endif // dTRIMESH_GIMPACT
161 #else
162 dIASSERT(false); // Should only be called when trimesh is enabled
163 #endif
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)
178 #if dTRIMESH_ENABLED
179 void *pv_DataInstance = (void *)vValueData;
180 FreeTrimeshCollisionLibraryData(pv_DataInstance);
181 #else
182 dIASSERT(false); // Should only be called when trimesh is enabled
183 #endif
187 #endif // #if dTLS_ENABLED