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 interface.
35 #ifndef _ODE_ODETLS_H_
36 #define _ODE_ODETLS_H_
45 struct TrimeshCollidersCache
;
49 OTI_DATA_ALLOCATION_FLAGS
,
50 OTI_TRIMESH_TRIMESH_COLLIDER_CACHE
,
51 OTI_TRIMESH_COLLISION_LIBRARY_DATA
,
60 enum // Initialize() flags
62 MANUAL_DATA_CLEANUP
= 0x00000001,
65 static bool Initialize(unsigned uFlags
=0);
66 static void Finalize();
68 static void CleanupForThread();
71 static unsigned GetDataAllocationFlags()
73 // Must be a safe call as it is used to test if TLS slot is allocated at all
74 return (unsigned)(size_t)CThreadLocalStorage::GetStorageValue(m_htkStorageKey
, OTI_DATA_ALLOCATION_FLAGS
);
77 static void SignalDataAllocationFlags(unsigned uFlagsMask
)
79 unsigned uCurrentFlags
= (unsigned)(size_t)CThreadLocalStorage::UnsafeGetStorageValue(m_htkStorageKey
, OTI_DATA_ALLOCATION_FLAGS
);
80 CThreadLocalStorage::UnsafeSetStorageValue(m_htkStorageKey
, OTI_DATA_ALLOCATION_FLAGS
, (tlsvaluetype
)(uCurrentFlags
| uFlagsMask
));
83 static void DropDataAllocationFlags(unsigned uFlagsMask
)
85 unsigned uCurrentFlags
= (unsigned)(size_t)CThreadLocalStorage::UnsafeGetStorageValue(m_htkStorageKey
, OTI_DATA_ALLOCATION_FLAGS
);
86 CThreadLocalStorage::UnsafeSetStorageValue(m_htkStorageKey
, OTI_DATA_ALLOCATION_FLAGS
, (tlsvaluetype
)(uCurrentFlags
& ~uFlagsMask
));
89 static TrimeshCollidersCache
*GetTrimeshCollidersCache()
91 return (TrimeshCollidersCache
*)CThreadLocalStorage::UnsafeGetStorageValue(m_htkStorageKey
, OTI_TRIMESH_TRIMESH_COLLIDER_CACHE
);
94 static void *GetTrimeshCollisionLibraryData()
96 return (void *)CThreadLocalStorage::UnsafeGetStorageValue(m_htkStorageKey
, OTI_TRIMESH_COLLISION_LIBRARY_DATA
);
100 static bool AssignDataAllocationFlags(unsigned uInitializationFlags
);
102 static bool AssignTrimeshCollidersCache(TrimeshCollidersCache
*pccInstance
);
103 static void DestroyTrimeshCollidersCache();
105 static bool AssignTrimeshCollisionLibraryData(void *pv_DataInstance
);
106 static void DestroyTrimeshCollisionLibraryData();
109 static void FreeTrimeshCollidersCache(TrimeshCollidersCache
*pccCacheInstance
);
110 static void FreeTrimeshCollisionLibraryData(void *pv_DataInstance
);
113 static void _OU_CONVENTION_CALLBACK
FreeTrimeshCollidersCache_Callback(tlsvaluetype vValueData
);
114 static void _OU_CONVENTION_CALLBACK
FreeTrimeshCollisionLibraryData_Callback(tlsvaluetype vValueData
);
117 static HTLSKEY m_htkStorageKey
;
121 #endif // dTLS_ENABLED
124 #endif // _ODE_ODETLS_H_